Hello. Before I begin, Yes, I have read and searched the forums for my answer and I'm still baffled.
In the code below, when I start the program I'm trying to get LED1 to illuminate using a photoresistor which is the visual input for me to depress the pushbutton. It doesn't work for whatever reason. I have looked at it and tried several different coding configurations for LED 3 but it still doesn't work. The rest of the program works as designed. What am I overlooking? Thanks for any help
#include<LiquidCrystal.h>
#include<Servo.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
Servo startingGate;
const byte buttonPin = 3; //starting line button for "GO"
const byte servoPin = 2;
const byte finishSensor1Pin = A0;
const byte finishSensor2Pin = A1;
const int darkThreshold = 500;
int LED1 = 7; //lane 1 win light
int LED2 = 6; //lane 2 win light
int LED3 = 43; //prestage light
int finishSensor1;
int finishSensor2;
boolean finishFlag = false;
long startTime;
long stopTime;
float raceTime;
void setup()
{
Serial.begin(9600); // initializes servo for starting line
pinMode(buttonPin, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
startingGate.attach(servoPin, 1000, 2000);
startingGate.write(0);
lcd.begin(16, 2);
lcd.clear();
lcd.print("Drag Strip Timer"); //initial display Line 1 on lcd
lcd.setCursor(0, 1);
lcd.print("Push to start!"); //inital display Line 2 on lcd
while (digitalRead(buttonPin) == HIGH)
{
}
lcd.clear();
lcd.print("Go!"); //displayed after race start
digitalWrite(LED1, HIGH); //turns on win light upon reset
digitalWrite(LED2, HIGH); //turns on win light upon reset
digitalWrite(LED3, LOW);
startingGate.write(180);
startTime = millis();
}
void loop()
{
//read the finish sensors at the same time
finishSensor1 = analogRead(finishSensor1Pin);
finishSensor2 = analogRead(finishSensor2Pin);
if (finishFlag == false)
{
//car #1 crosses first
if ((finishSensor1 < darkThreshold) && (finishSensor2 > darkThreshold))
{
stopTime = millis();
raceTime = stopTime - startTime;
finishFlag = true;
digitalWrite(LED1, LOW);
lcd.clear();
lcd.print("Winner Lane #1"); //displayed if lane 1 photeresistor changes state before lane 2
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(raceTime / 1000, 3);
}
//car #2 crosses first
else if ((finishSensor2 < darkThreshold) && (finishSensor1 > darkThreshold))
{
stopTime = millis();
raceTime = stopTime - startTime; //formula used to determine elapsed time
finishFlag = true;
digitalWrite(LED2, LOW);
lcd.clear();
lcd.print("Winner Lane #2"); //displayed if lane 2 photeresistor changes state before lane 1
lcd.setCursor(0, 1);
lcd.print("ET: "); //displays winning elapsed time
lcd.print(raceTime / 1000, 3);
}
}
}