Sup guys!
So me and my friend are doing a school project and the assignment is to create a traffic light. We are also using a LDR sensor. When we are programing we are thinking to do in the order: Light is red, if sensor senses over a sertain number we run the other code that is going to yellow, green and then yellow, red and then doing it all again (when the sensor is trigged). The problem is when we try to use the terms: If or Else or If Else. We cant seem to get this to work and we are asking for your help.
This is the code as it is now:
int red = 6;
int yellow = 5;
int green = 4;
int DELAY_green = 7000;
int DELAY_yellow = 2000;
int DELAY_red = 7000;
#define LDRpin A1
int LDRValue = 0;
void setup() {
Serial.begin(9600);
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);
}
void loop()
{
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
if
(analogRead)(0<200);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(1000000);
else if
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(red, HIGH);
delay(DELAY_yellow);
digitalWrite(green, HIGH);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(DELAY_green);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(red, LOW);
delay(DELAY_yellow);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
}
The error message is as follows:
WARNING: Category 'Education' in library EducationShield is not valid. Setting to 'Uncategorized'
/Users/01is01/Documents/Arduino/sketch_mar27a/sketch_mar27a.ino: In function 'void loop()':
sketch_mar27a:30: error: 'else' without a previous 'if'
else if
^
sketch_mar27a:31: error: expected '(' before 'digitalWrite'
digitalWrite(green, LOW);
^
exit status 1
'else' without a previous 'if'
We are thankful for any replies we can get!