I have written a very simple piece of code that lights a white LED when a button is pressed. I want the button state to be stored so the LED remains on until I press the button again.
I get the following error: Compilation error: 'else' without a previous 'if'
I can't work out where its gone wrong:
int whiteledPin = 8;
int buttonPin = 4;
int lastState = digitalRead(4);
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(whiteledPin, OUTPUT);
}
void loop() {
int currState = digitalRead(buttonPin);
if (currState == LOW); {
digitalWrite(whiteledPin, HIGH);
}
else {
digitalWrite(whiteledPin, LOW);
}
lastState = currState;
}