this project is a switch case i whit one piezo it works but now in case 5 i while 2 piezo als trigger.
case 5:
StartTime = millis(); // start timer
hit = 0; // reset the number of times the target has been hit. you have 3 shots until it moves to the next one
delay(RandomTime);
while(hit < 1){
// read sensors for random mode
HeadSensorReadingRandom = analogRead(HeadSensor);
TorsoSensorReadingRandom = analogRead(TorsoSensor);
LegSensorReadingRandom = analogRead(LegSensor);
LegSensor1ReadingRandom = analogRead(LegSensor1);
// light the target to hit
digitalWrite(Led4yellowPin, 1);
digitalWrite(Led4redPin, 0);
digitalWrite(Led4greenPin, 0);
digitalWrite(Led1yellowPin, 1);
digitalWrite(Led1redPin, 0);
digitalWrite(Led1greenPin, 0);
ActualTime = millis(); // measure the actual time
Timeout = ActualTime - StartTime; // calculate the time that has passed since the target was active
// if the sensor reading is greater than the threshold:
if (LegSensor1ReadingRandom >= sensitivity || HeadSensorReadingRandom >= sensitivity ) {
while(HeadSensorReadingRandom>= false)
{
digitalWrite(Led4yellowPin, 0);
digitalWrite(Led4redPin, 0);
digitalWrite(Led4greenPin, 0);
}
if(LegSensor1ReadingRandom>= false)
{
digitalWrite(Led1yellowPin, 0);
digitalWrite(Led1redPin, 0);
digitalWrite(Led1greenPin, 0);
}
// update the LED pin itself:
wright(3);
hit = 3;
}
//if the target has been active for too long (more than 20s), you've timed out
if (Timeout >= 4000) {
wrong(15);
hit = 3;
RandomOFF = RandomOFF + 200;
delay(15000);
}
}
// one less target to the end of random mode
RandomOFF = RandomOFF + 1;
break;