Go Down

Topic: 'switchstate' was not declared in this scope Problem whit 02 project (Read 1 time) previous topic - next topic

lloll

Code: [Select]
int swithcState = 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(3, LOW); // red LED
  digitalWrite(3, LOW); // red LED
  }
  else { // the button is pressed
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);

    delay(250); //wait for a quarter second
    //togle the LEDs
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    delay(250); //wait for a quarter second
  }
} //go back to the beginning of the loop



And another question do you have to do these
Code: [Select]
//wait for a quarter second or no?

akatchi

Because you declared 'int swithcState', not switchState, you simply spelled it wrong.
And that's what the error is telling you 'switchState' not declared, you declared swithcState.

And no you don't have to use a quarter second delay, you can make it 1 second or 2 if you want to (or whatever you like), but if you completely remove the delays you won't see it blinking.

lloll

Oh thanks im stupid .I didnt mean the delay i ment the //no comment things that go grey

akatchi

Oh thanks im stupid .I didnt mean the delay i ment the //no comment things that go grey
Ohh sorry I misunderstood that!
No you don't, everything with '//' in front that becomes grey will the sketch basically 'ignore'. So if you remove it, it won't change anything. They added it for users to know why and what's happening :).


Gabriel_swe

You even got 3 different spelling

switchState
swithcState
switchstate

Go Up