This is what its supposed to do.
Read the voltage coming into the analogue inputs 0, 1, and 2. If the voltage drops under 2 volts in input 0 the yellow light will turn on while the other LED's are off, if the input in 0, and 1 go below 2 volts the green light will turn on, and the other LED's will be off, and if the voltage in 1,2 and, 3 go below 2 volts, than the red light will turn on and the other led's will be off.
The code compiles but is just not working. I checked the voltages going into the analogue inputs with a volt meter and everything seems to be fine.
int led1 = 4; //Yellow
int led2 = 5; // Green
int led3 = 6; // Red
int led4 = 12;
int led5 = 13;
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
void loop() {
unsigned int d1 = analogRead(0);
unsigned int d2 = analogRead(1);
unsigned int d3 = analogRead(2);
if ((2 <= d1) && (2 <= d2) && (2 <= d3))
{
digitalWrite(led1, LOW); //Yellow
digitalWrite(led2, LOW); // Green
digitalWrite(led3, LOW); // Red
}
else if ((d1 <= 2) && (2 <= d2) && (2 <= d3))
{
digitalWrite(led1, HIGH); //Yellow
digitalWrite(led2, LOW); // Green
digitalWrite(led3, LOW); // Red
}
else if ((d1 <= 2) && (d2 <= 2) && (2 <= d2))
{
digitalWrite(led1, LOW); //Yellow
digitalWrite(led2, HIGH); // Green
digitalWrite(led3, LOW); // Red
}
else if ((d1 <= 2) && (d2 <= 2) && (d3 <= 2))
{
digitalWrite(led1, LOW); //Yellow
digitalWrite(led2, LOW); // Green
digitalWrite(led3, HIGH); // Red
}
}