I have two piezo now i want that, if i trigger one piezo the led go out then i want that the piezo wait for the second piezo is triggert then the second led is going out then break . Can some one help me
How far did you get with this?
...Nobody can write the program for you because we don't know where/how the piezos or LEDs are connected, or how much signal you're getting out of the piezo, etc. Plus, this a DIY forum for people who want to learn and do things themselves.
...You're going to have to make an outline of what your code should do.
You'll need [u]If-statements[/u] because if something happens you want to turn on an LED, etc.
You may also need two (or more) [u]loops[/u], so when you're done with the 1st loop, you can move-on to the next one and wait for the 2nd piezo trigger, etc. (There are 3 kinds of loops in addition to the main loop.)
Take it one step at a time and "develop" your code, testing as you go-along.... Sometimes you'll have to add some extra code just for testing, such as some print statements so you can "see" what your program is doing before you're done, etc. Do NOT try to write the whole program at once!
Then, when if you run into a problem that you can't figure out, post your code and maybe someone can help you.
You might want to start with the Analog Read Serial Example to see what you're getting from the piezo and if you're getting 5V (1023 on the analog) you may be able to read it digitally. (And, you might want to take the delay out of the Analog Read Serial Example because you want the best chance of "catching" the peaks.)
It may turn-out that you need to use interrupts, but let's not worry about that yet.
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;