Brand new to Arduino
just tried writing the code for the Spaceship Interface in the starter kit and I keep getting this error message. I believe I have written it the way the book calls for but I'm sure I have done something wrong. Thanks for any help out there...
Arduino: 1.8.13 (Mac OS X), Board: "Arduino Uno"
/Users/bowmanoftexas/Documents/Arduino/space_ship_control_1/space_ship_control_1.ino: In function 'void loop()':
space_ship_control_1:10:1: error: 'switchState' was not declared in this scope
switchState = digitalRead(2);
^~~~~~~~~~~
/Users/bowmanoftexas/Documents/Arduino/space_ship_control_1/space_ship_control_1.ino:10:1: note: suggested alternative: 'switchstate'
switchState = digitalRead(2);
^~~~~~~~~~~
switchstate
exit status 1
'switchState' was not declared in this scope
int switchstate = 0;
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
switchState = digitalRead(2);
// this is a comment
if (switchState == LOW) {
//the button is not pressed
digitalWrite(3, HIGH); // green LED
digitalWrite(4, LOW); // red LED
digitalWrite(5, LOW); // red LED
}
else{ // the button is pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); // wait for a quarter second
// toggle the leds
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
} // go back to the beginning of the loop