I just finished using a public secret knock pattern program to activate a series of different led strips, but I can't for the life of me figure out how to get the program to listen for two different patterns at once. I have been able to get them stored, but the program only listens for the first one in the loop. Please help! Here's the void setup and loop code. The full code is attached.
void setup() {
pinMode(leftBlinker, OUTPUT);
pinMode(rightBlinker, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(leftprogramSwitch, INPUT);
pinMode(rightprogramSwitch, INPUT);
Serial.begin(9600); // Uncomment the Serial.bla lines for debugging.
Serial.println("Program start."); // but feel free to comment them out after it's working right.
digitalWrite(greenLED, HIGH); // Green LED on, everything is go.
}
void loop() {
// Listen for any whistle at all.
whistleSensorValue = analogRead(whistleSensor);
if (digitalRead(leftprogramSwitch)==HIGH){ // is the left program button pressed?
programLeftButtonPressed = true; // Yes, so lets save that state
digitalWrite(redLED, HIGH); // and turn on the red light too so we know we're programming.
} else {
programLeftButtonPressed = false;
digitalWrite(redLED, LOW);
}
if (digitalRead(rightprogramSwitch)==HIGH){ // is the right program button pressed?
programRightButtonPressed = true; // Yes, so lets save that state
digitalWrite(redLED, HIGH); // and turn on the red light too so we know we're programming.
} else {
programRightButtonPressed = false;
digitalWrite(redLED, LOW);
}
if ((whistleSensorValue >=threshold) && (digitalRead(rightprogramSwitch)==LOW)){
listenToSecretLeftWhistle();
}
if ((whistleSensorValue >=threshold) && (digitalRead(leftprogramSwitch)==LOW)){
listenToSecretRightWhistle();
}
}
Bike_Blinkers_Left_and_Right.ino (16.9 KB)