willjones360:
Unfortunatly I am going to be fitting the hardware into a pre-existing machine. so i need to use the buttons that are already there! If theres a way to treat those buttons as if they are a keypad that would be grand as there seems to be a lot of reading materials about using keypads online!
Assuming nothing else will be connected to the buttons, just the wires to the Arduino, you will be able to wire them in a matrix thus saving a few pins. That's basically how keypads are wired.
willjones360:
The user will always be pushing 3 buttons, and theres a reset button if the wrong buttons are pressed, which i would use to set the count back to zero.
You still need this timeout, as a user is not guaranteed to press reset or exactly three buttons.
slipstick:
Save the value just means put it in a variable. So put the number of the first button pressed into a variable called something like firstnum (so if it's button number 3 set firstnum=3). Do the same for second and third buttons into secondnum, thirdnum.
In OPs specific case I would save them in a char array, which later can be used as file name.
So you'd get something like this:
byte nPresses = 0;
const byte buttonPin[10] = {0, 1, 2, ..., 9}; // I'm lazy here. Pins that connect buttons for 0 - 9, in that order.
const byte nButtons = 10; // The number of buttons in use.
char song[3];
void loop() {
for (byte i = 1; i < nButtons; i++) {
if (digitalRead(buttonPin[i])) == LOW) { // Do add debouncing & state checking.
song[nPresses] = i+48; // ASCII code for '0' - '9'
nPresses++;
}
}
if (nPresses == 3) { // Three buttons have been pressed: play the requested song.
nPresses = 0;
playSong(song);
}
}
A press on the reset button will simply set nPresses back to 0, that's all you need to do there.
Now think about what to do if a song is requested when another song is being played. Ignore it? Queue it (up to how many songs)? Stop the current song, start the new one?