Starter Kit Spaceship Interface Not declared in Scope error message

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

switchstate is NOT switchState - case does matter.

Thanks!! I swapped both of them and it worked!! However the book lists it as switchState... now I know!! Cheers!!

techsytex:
However the book lists it as switchState

That's correct, but the book uses switchState everywhere. You can use any case you like. You just need to be consistent.

The book even even gives some nice advice about that in this project:

Case sensitivity
Pay attention to the case
sensitivity in your code.
For example, pinMode is the name of
a command, but pinmode will produce
an error.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.