In the function countdown:
I set the pins to wires (one for automatic detonation[Wire_1] and 3 for defusing sequence[Wire_2–>Wire_4–>Wire_3])
defusePin = WIRE_2;
defusePin2 = WIRE_4;
defusePin3 = WIRE_3;
detPin = WIRE_1;
DetState = 0;
Then in the main loop of the function:
while ((countdownSeconds > 0) && (!defused)) {
for(int i=0;i<10000;i++) {
if (digitalRead(detPin) == HIGH) {
countdownSeconds = 0;
break;
}
// old stuff commented ;-)
/*if (digitalRead(defusePin) == HIGH) {
defused = true;
break;
}*/
//enters the sequence:
if ((digitalRead(defusePin) == HIGH) && (DetState == 0))
{
DetState++;
beep(4200, 30); //just a noise for comfirmation :)
}
if ((digitalRead(defusePin2) == HIGH) && (DetState < 1))
{
countdownSeconds = 0;
}
else if ((digitalRead(defusePin2) == HIGH) && (DetState == 1))
{
DetState++;
beep(4200, 30);
}
if ((digitalRead(defusePin3) == HIGH) && (DetState < 2))
{
countdownSeconds = 0;
}
else if ((digitalRead(defusePin3) == HIGH) && (DetState == 2))
{
defused = true;
}
}
As you can see, it’s pretty simple , but works like a charm 🙂