I fixed the braces, but now I have an error stating I have an "else" without a previous "if" function. It's referring to line 27 of the code below. How would I write in an "if" without wrecking the current function?
Could it be a "mirrored" version of line 16 where I copy that but replace LOW with HIGH?
Could it be a "mirrored" version of line 16 where I copy that but replace LOW with HIGH?
Code:
int switchState = 0;
const unsigned long event_1 = 3000;
const unsigned long event_2 = 7000;
unsigned long previousTime = 0;
unsigned long currentTime = 0;
void setup(){
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop(){
currentTime = millis();
switchState = digitalRead(2);
if (switchState == LOW) {
digitalWrite(3, HIGH); // green led
digitalWrite(4, LOW); // red led
previousTime = millis();
}
else {
if (currentTime - previousTime >= event_1){
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
}
}
else {
if (currentTime - previousTime >= event_2){
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
}
}