Hello, I'm a student working on a project that takes project 3 and 14 from the Earthshine Design pdf and combine them to create a basic red yellow and green traffic light that runs normal during the day and when the light dependent resistor(LDR) is covered or reads "night time" the order of the lights changes. I'd like it so the yellow light stays on and flashes during night but once light hits the LDR the yellow light then turns off and the lights change back to normal.
Below I have attached two photos of how I have the board laid out currently along with the code I'm starting off with. The code is just a copy and paste of the two projects. I'm not sure if I have the board wired right so even if I was able to get the code finished I'm not sure if the board would light up. As for the code I was planning to put in an if statement that after every light turned on normally such as red, green, yellow then red it would check if it night. If night then it would turn just the yellow on for lets say 2 seconds then do a check if it's still night. Any help or input on this would be greatly appreciated.
//Project 14 - Light Sensor
// Pin we will connect to LED
int ledPin = 9;
// Pin connected to LDR
int ldrPin = 0;
// Value read from LDR
int lightVal = 0;
// Project 3
int ledDelay = 10000; // delay in between changes
int redPin = 10;
int yellowPin = 9;
int greenPin = 8;
void setup()
{
// Set both pins as outputs
pinMode(ledPin, OUTPUT);
// Project 3
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop()
{
// Read in value from LDR
lightVal = analogRead(ldrPin);
// Turn LED on
digitalWrite(ledPin, HIGH);
// Delay of length lightVal
delay(lightVal);
// Turn LED off
digitalWrite(ledPin, LOW);
// Delay again
delay(lightVal);
// Project 3
// turn the red light on
digitalWrite(redPin, HIGH);
delay(ledDelay); // wait 5 seconds
digitalWrite(yellowPin, HIGH); // turn on yellow
delay(2000); // wait 2 seconds
digitalWrite(greenPin, HIGH); // turn green on
digitalWrite(redPin, LOW); // turn red off
digitalWrite(yellowPin, LOW); // turn yellow off
delay(ledDelay); // wait ledDelay milliseconds
digitalWrite(yellowPin, HIGH); // turn yellow on
digitalWrite(greenPin, LOW); // turn green off
delay(2000); // wait 2 seconds
digitalWrite(yellowPin, LOW); // turn yellow off
// now our loop repeats
}