I am trying to put together a project that when both a microphone and a pressure sensor both give a peak reading a output is triggered however at present i am experimenting with simple push buttons before using analog inputs.
what I am trying to achieve is that when both buttons are pressed or pressed within a given time of each other (ie. one button is pushed and the other is pushed within 2 seconds) that an event is triggered.
any help at all getting this to work with at least the buttons would be greatly appreciated.
so far this is what i have, but have been having trouble getting the two buttons to operate independently, the LedPins are currently just being used for testing purposes. I havnt got this far yet but the intention was that when both counters = 1 they would trigger an event.
int buttonPin1 = 1;
int buttonPin2 = 2;
int ledPin1 = 9;
int ledPin2 = 10;
int counter1 = 0; //using a counter to determine button state
int counter2 = 0;
int buttonState1;
int buttonState2;
void setup(){
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop(){
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH){
counter1++;
if (counter1 >1){
counter1 = 0;
}
}
if(buttonState2 == HIGH){
counter2++;
if (counter2 >1){
counter2 = 0;
}
}
if (counter1 == 1){
digitalWrite(ledPin1, HIGH);
}
else if(counter1 != 1){
digitalWrite(ledPin1, LOW);
}
if (counter2 == 1){
digitalWrite(ledPin2, HIGH);
}
else if(counter2 != 1){
digitalWrite(ledPin2, LOW);
}
if(counter1 ==1){ //this part had the intention of resetting each counter to 0 after 1 second.
delay(1000);
counter1--;
}
if(counter2 ==1){
delay(1000);
counter2--;
}
}