I modified reaction timer program and added a piezo as a sensor to start program by touching a plate and a led (visual cue) to light when random time ends and led goes out and time stops when plate is touched again, works great. I tried adding a piezo as a buzzer (audio cue) that starts the same time when led light comes on, but want it to go out 250ms latter. having no luck, seems to affect the way program runs. and for some reason the counter only goes up to 32 seconds and stop count and each display dp lights up. Can anyone help me with the code and why counter stop at 32 seconds? Code below
#include
unsigned long start, stop;
const int knockSensor = A1;
const int ledPin = 9;
cont int buzzer = 10
void setup() {
randomSeed(analogRead(0));
pinMode(ledPin, OUTPUT);
DigitShield.begin();
DigitShield.setPrecision(2);
DigitShield.setBlank(true);
}
void loop() {
while (analogRead(knockSensor) <=10);// wait until plate is touched
DigitShield.setBlank(true);// turn off the display
delay(random(2000, 5000));// delay from 2 to 5 seconds
digitalWrite(ledPin, HIGH);
tone(10,2000);
start = millis();
if (millis() – start >=250){
noTone(10);
DigitShield.setBlank(false);
while (true) {
DigitShield.setValue((int)(millis() – start)/1000.0);
if (analogRead(knockSensor) >=1) {
stop = millis();
break;
}
}
digitalWrite(ledPin, LOW);
DigitShield.setValue((int)(stop-start)/1000.0);
DigitShield.setBlank(false);
delay(1000);
}