Hello everyone, I'm new to the arduino and this forum. I've made a breadboard arduino and timer shield for cowboy fast draw. The code I'm using works, but when timer count gets beyond "9.9.9.9" I get error " . . . . " displayed on each LED,, which is expected.. I want the timer to reset if timer count's >= 5 seconds if the sensor does not detect a hit on the target.. The code I added using "else if" is got me stumped, Iv'e been working on the problem for hours and wonder if someone can assist me with the code. I get error"cowboy_fast_draw_timer2:45: error: expected unqualified-id before 'else'
#include <DigitShield.h>
unsigned long start, stop;
const int knockSensor = A1;
const int ledPin = 13;
void setup() {
randomSeed(analogRead(0));
pinMode(ledPin, OUTPUT);
DigitShield.begin();
DigitShield.setPrecision(3);
DigitShield.setBlank(true);
}
void loop() {
while (analogRead(knockSensor) <=10); // wait until sensor greater than 10
DigitShield.setBlank(true); // turns off the display
DigitShield.setLeadingZeros(true); // start display with zero's
delay(3000);
for (int i=0; i<3; i++) // declares i, tests if less
{ // than 10, increments i by 1 until i equals 3
digitalWrite(13, HIGH); // turns pin 13 on
delay(500); // pauses for 1/2 second
digitalWrite(13, LOW); // turns pin 13 off
delay(500); // pauses for 1/2 second
}
delay(random(2000, 5000)); // delay from 2 to 5 seconds
digitalWrite(ledPin, HIGH); // light turns on
start = millis();
DigitShield.setBlank(false); // display turn on starts counting
while (true) {
DigitShield.setValue((long)(millis() - start)/1000.0);
if (analogRead(knockSensor) >=10) { // if sensor greater than 10 counter stops
stop = millis();
break; // stop's while loop
}
}
digitalWrite(ledPin, LOW);
DigitShield.setValue((long)(stop-start)/1000.0); // calculate's time
DigitShield.setBlank(false); // display's time
delay(1000);
}
else if DigitShield.setValue((long)(stop-start)/1000.0)>=5.000
{
digitalWrite(ledPin, LOW);
DigitShield.setLeadingZeros(true);
DigitShield.setBlank(false);
delay(1000);
}