I have an unqualified-id before else, and I don't know how to solve it.
int buttonPin = 2; // set variables for component pins
int redLED = 4;
int buttonPress; // declare variable for the button state
char answer;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(redLED, OUTPUT);
}
void loop() {
buttonPress = digitalRead(buttonPin); // set variable to button pin reading
if (buttonPress == HIGH) { // if button is pressed, turn LED on
answer = shouldItlight();
if (answer == 'Y') {
digitalWrite(redLED, HIGH);
} else if (answer == 'N') {
digitalWrite(redLED, LOW); // otherwise, LED is off
}
}
}
else if(buttonPress == LOW) {
digitalWrite(redLED, LOW);
}
char shouldItlight() {
char yesorno;
Serial.println(" press y to light the button.");
while (!Serial.available()) {}
yesorno = Serial.read();
return yesorno; //returns a character
}