code

The third last line "switchState++;" keeps coming up as "switchState++; exit status 1 switchState++; was not declared in this scope. I do not understand what is going on or how to fix, please can anyone help?

int switchPin = 2;
int motorPin = 3;
int switchTate = 0;

void setup() {
analogWrite (motorPin, 0) ;
pinMode (13, OUTPUT) ;
digitalWrite (13, LOW) ;
attachInterrupt (0, changeMotor, RISING) ;
}

void loop() {
}

void changeMotor () {
switch (switchState) {
case 0:
analogWrite (motorPin, 75);
digitalWrite (13, HIGH);
break;
case 1:
analogWrite (motorPin 150);
digitalWrite (13, LOW);
break;
case 2:
analogWrite (motorPin, 250);
digitalWrite (13, HIGH);
break;
case 3:
analogWrite (motorPin, 0);
digitalWrite (13, LOW);
}
switchState++;
if (switchState == 4)
switchState = 0;
}

int switchTate = 0;

int switchState = 0;

Leo..

thats not the line that is the problem its switchState++; that is the problem.

No, go back look again. In your declaration you declare a variable switchTate. Then in the code you refer to switchState, which has never been declared, and the compiler is telling you so.

You even capitalized the mistake. :slight_smile:

Thanks everyone!

Important lesson here. The compiler throws an error when IT gets confused. This is not necessarily where you have made the error.