ummm i am unable to merge that code with my code
this is one of the action should be performed when the button is pushed less than 2 seconds; i would like to add another action when buttonPin is pressed more than 2 seconds
in the first action it emitts a sound via mp3 board and count the number of pushed times (that is needed for other purpose)
i added a debounce time to avoid false start
// SELECTOR BEGIN
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
if ((millis() - lastDebounceTime) > debounceDelay){
// control that input is HIGH (button pressed)
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == LOW) {
// play file 004.mp3 in folder advert02 -- switching sound
Serial.write(0x7E);
Serial.write(0x07);
Serial.write(0xA0);
Serial.write(0x30);
Serial.write(0x32);
Serial.write(0x30);
Serial.write(0x30);
Serial.write(0x34);
Serial.write(0x7E);
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
TrackCounter = 0;
lastDebounceTime = millis(); //set the current time
}
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// SELECTOR END
buttonPin it's already declared as
const int buttonPin = 2; // WEAPON SELECTOR
pinMode(buttonPin, INPUT);
in your code i should change as "INPUT_PULLUP" and i dont' know if it's ok..