Hi,
I have an arduino code that is part of a music piece. the code have a button that on press it count and go to different "scene"
so when I press first time button count is 1 and therefore scene 1 is playing.
after 10 minute or so I'm pressing again the button. Button count is now 2 and therefore scene 2 is playing. after some more time I'm pressing the button again, therefore button count is 3 and scene 3 is playing.
could happen that because of an exitment of the moment I'm pressing the button twice and now the count is 1 step ahead from what it should be. I would like to have the option that a long press of lets say 3 seconds will count one step back so I will have the option to go back if made a mistake.
How can I do so ?
EDIT:
I found a Solution thank to this post by LarryD
void buttonPress ()
{
byte currentButtonState = digitalRead (switchPin);
if (lastButtonState != currentButtonState) {
lastButtonState = currentButtonState;
//******************
//has the switch been pushed ?
if (currentButtonState == PUSHED)
{
//record the time the switch closed
timePushed = millis();
}
//******************
//switch has been released
else
{
//calculate the time the switch was closed
timePushed = millis() - timePushed;
if(timePushed < 1800)
{
buttonPressCount++;
millisTimePress = currentMillis;
Serial.print("buttonPressCount: ");
Serial.println(buttonPressCount);
Serial.print("TimePress: ");
Serial.println(millisTimePress);
digitalWrite (ledPin, ! digitalRead (ledPin));
}
else if (timePushed > 2000)
{
buttonPressCount--;
Serial.print("buttonPressCount: ");
Serial.println(buttonPressCount);
Serial.print("TimePress: ");
Serial.println(millisTimePress);
digitalWrite (ledPin, ! digitalRead (ledPin));
}
}
}
}