so I started a project yesterday in which i am trying to get an event to happen when 2 buttons are pressed within a certain time of each other ie. button 1 is pushed and within 2 seconds button 2 is pushed and then an LED lights up.
I got a bit of help yesterday but am still struggling to get it to work any help pointing out where i am going wrong would be greatly appreciated.
const int buttonPin1 = 1;
const int buttonPin2 = 2;
const int ledPin1 = 9;
unsigned long TS1 = 0;
unsigned long TS2 = 0;
void setup(){
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(ledPin3,OUTPUT);
}
void loop(){
if(buttonPin1 == HIGH){
TS1 = millis();
}
if(buttonPin2 ==HIGH){
TS2 = millis();
}
if((TS1 != 0) && (TS2 != 0) && (abs(TS1-TS2) < 2000)){
digitalWrite(ledPin1, HIGH);
}
else{
digitalWrite(ledPin1, LOW);
}
}