Hi,
I was trying to get Arduino to turn on the light as green when it is exposed to light, then after 10 seconds to turn blue, and after 5 seconds to turn red. I figured that the best way would be to use a rgb led. I have done that, and added the light sensor. The problem I am having is that I cant get the light sensor code to work. Also, the light that first comes up is green, but rather blue. Here is the code I am using:
int LEDGreen = 10;
int LEDPurple = 9;
int LEDRed = 11;
int lightLevel = 0;
int counter = 0;
int lightPin = 12;
void setup ()
{
pinMode(LEDGreen, OUTPUT);
pinMode(LEDPurple , OUTPUT);
pinMode(LEDRed, OUTPUT);
pinMode (lightPin, OUTPUT);
}
void loop()
{
lightLevel = analogRead (lightPin);
if (lightLevel > 500);
{
counter = counter + 1;
}
if (counter = 10)
{
digitalWrite (lightPin, HIGH);
}
delay (1000);
setColor(255, 0, 0); // red
delay(15000);
setColor(0, 255, 0); // green
delay(5000);
setColor(255, 255, 0); // yellow
delay(10000);
}
void setColor(int green, int purple, int red)
{
analogWrite(LEDGreen, green);
analogWrite(LEDPurple, purple);
analogWrite(LEDRed, red);
}
Please let me know what I am doing wrong. Thank you