Just when I think I have earned something, I get kicked below the belt again. LOL. I constructed the following code to use 2 photoresistors to turn on 2 LEDs. It works as it should. Here is the code.
They are wired as described in the Arduino examples.
This program uses 2 photoresistors at the end of the coding to stop the timer and determine the winner also. I'm wanting to run the 1st program to turn on 2 LEDS and once this has happened, allow that to trigger the sequential countdown in the second program. that starts on line 43-44. Any help would be appreciated..
PRE-STAGE CODING car 1 uses pins A5 and pin 50. The photoresistor value is 120. Car 2 uses A4 and pin 48 and the value changes to 120
int ldr=A4;//Set A4(Analog Input) for LDR2.
int value=0;
void setup() {
Serial.begin(9600);
pinMode(48,OUTPUT);
}
void loop() {
value=analogRead(ldr);//Reads the Value of LDR(light).
if(value<=200)
{
digitalWrite(48,HIGH);//Makes the LED glow in Dark.
}
else
{
digitalWrite(48,LOW);//Turns the LED OFF in Light.
}
}
_________________________________________________________________________________________________
Second code starts here.....
`#include<LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
const byte buttonPin = 3; //starting line button for "GO"
const byte finishSensor1Pin = A0;
const byte finishSensor2Pin = A1;
const int darkThreshold = 250;
int LED6 = 6; //lane 1 win light used to determine winner
int LED7 = 7; //lane 2 win light used to determine winner
int LED1 = 41;
int LED2 = 43;
int LED3 = 45;
int finishSensor1;
int finishSensor2;
boolean finishFlag = false;
long startTime;
long stopTime;
float raceTime;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(LED1, OUTPUT); //Configures the specified pin to behave as an output.
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(4000);
digitalWrite(LED1, LOW);
delay(1000);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
delay(1000);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, LOW);
delay(4000);
digitalWrite(LED3, HIGH);
lcd.begin(16, 2);
lcd.clear();
lcd.print("Drag Strip Timer"); // display Line 1 on lcd
lcd.setCursor(0, 1);
lcd.print("Push to start!"); // display Line 2 on lcd
while (digitalRead(buttonPin) == HIGH)
{
}
lcd.clear();
lcd.print("Go!");
lcd.setCursor(0, 1);
lcd.print("Who will win?");
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(LED6, 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(LED7, 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);
}
}
}
`