I'm trying to use the nintendo controller to control a lighting system. I want an action to occur when I push up three times. The code should expire if the last button push is longer than 500ms. I'm having a hard time sensing this for some reason. Here's the code so far.
#include <NESpad.h>
// put your own strobe/clock/data
NESpad nintendo = NESpad(2,3,4);
unsigned long codeWindow = 0;
unsigned long time = 0;
int codeCount = 0;
byte state = 0;
void setup() {
}
void loop() {
state = nintendo.buttons();
//testing for button push
if (state & NES_UP){
//recording time when button was pushed
time = millis();
codeCount = 1;
}
//testing for button release inside a 500ms time window
if (!(state & NES_UP) && (millis() - time) < 500){
codeCount = 2;
}
//Print out
Serial.begin(4800);
Serial.println(codeCount);
delay(20);
}
Just trying to sense the push and release of the up button within 500ms.