Good evening. I've been receiving an error, and i dont know how to fix it. I'm still new to programming. Thanks.
Error:
sketch_jan15a:18:1: error: expected unqualified-id before 'if'
if (buttonState == HIGH)
sketch_jan15a:22:1: error: expected unqualified-id before 'else'
else
^
exit status 1
expected unqualified-id before 'if'
the code:
const int sensorPin = 4;
const int buttonPin = 5;
const int motorPin = 9;
int sensorState = 0;
int buttonState = 0;
void setup() {
pinMode(sensorPin, INPUT);
pinMode(buttonPin, INPUT);
pinMode(motorPin, OUTPUT);
}
void loop(){
sensorState = digitalRead(sensorPin);
buttonState = digitalRead(buttonPin);
}
if (buttonState == HIGH)
{
digitalWrite (motorPin, HIGH);
}
else
{
digitalWrite (motorPin, LOW);
}
the errors are at lines 18 and 22. Thanks.