• Quick Arduino Question.
    2 replies, posted
So I have to do a little project of my choice in one of my classes. I chose to create an MP3 player out of the Arduino that will play songs from a piezo buzzer and use pushbuttons to pause, play, and skip to the next song. I just wanted to know the best way to get the Arduino to pause the currently playing song and resume it when the user presses the button again. I've only just been introduced to the Arduino in this class so I know next to nothing about it, but is there a method that will help me do that? I've looked around online and can't find a definitive answer, but one idea I found was using while(digitalRead(pin) == 0) {} to run a function (in this case a song written in code) as long as the button is set LOW. Then when the button is set HIGH it will stop playing the song. But in this case I wouldn't know how to get the Arduino to start the song again where it left off. Thanks for any help!
What exactly do you need help with? The overall structure of the program of the playing sounds part specifically? Here's one possible general structure. [code] typedef enum { Playing, Paused } MODE; #define PLAY_BUTTON 1 #define PAUSE_BUTTON 2 MODE mode; void setup() { mode = Paused; pinMode(PLAY_BUTTON, INPUT); pinMode(PAUSE_BUTTON, INPUT); } void loop() { int in = LOW; if(mode == Paused) { in = digitalRead(PLAY_BUTTON); if(in == HIGH) { mode = Play; // code to resume state goes here } } else if(mode == Play) { in = digitalRead(PAUSE_BUTTON); if(in == HIGH) { mode = Paused; // code to save state goes here } } } [/code] You could just use a bool for playing/paused unless you want to have more possible states [editline]24th November 2014[/editline] Also there's [URL="http://facepunch.com/showthread.php?t=1250528"]already a thread [/URL]for programming help.
[QUOTE=thrawn2787;46566364]What exactly do you need help with? The overall structure of the program of the playing sounds part specifically? Here's one possible general structure. [code] typedef enum { Playing, Paused } MODE; #define PLAY_BUTTON 1 #define PAUSE_BUTTON 2 MODE mode; void setup() { mode = Paused; pinMode(PLAY_BUTTON, INPUT); pinMode(PAUSE_BUTTON, INPUT); } void loop() { int in = LOW; if(mode == Paused) { in = digitalRead(PLAY_BUTTON); if(in == HIGH) { mode = Play; // code to resume state goes here } } else if(mode == Play) { in = digitalRead(PAUSE_BUTTON); if(in == HIGH) { mode = Paused; // code to save state goes here } } } [/code] You could just use a bool for playing/paused unless you want to have more possible states [editline]24th November 2014[/editline] Also there's [URL="http://facepunch.com/showthread.php?t=1250528"]already a thread [/URL]for programming help.[/QUOTE] Thanks for the thorough example! And no I didn't want it to have more possible states, just simply play and pause. I pretty much just want the song to play then pause when a button is pressed, then resume where it left off when the button is pressed again. Edit: Thanks I'll go over to that thread from now on.
Sorry, you need to Log In to post a reply to this thread.