expected declaration before '}' token

here is my code.

#include <Stepper.h>

const int stepsPerRevolution = 200;

// initialize the stepper library on pins 6 through 9:
Stepper myStepper(stepsPerRevolution, 6, 7, 8, 9);

//initialize digital input for rotary encoder

#define outputA 10 //rotary A
#define outputB 11 //rotary B
#define outputC 12 //rotary switch

int mStep = 1; //set the number of step initialy to 1
int aState ;
int aLastState ;
int sState ;

void setup() {
// initialize the serial port:
//set digital pin to input for rotary
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
pinMode (outputC,INPUT);

void loop() {
aState = digitalRead(outputA); // Reads the “current” state of the outputA
sState = digitalRead(outputC); // read the state of the switch
// If the previous and the current state of the outputA are different, that means a Pulse has occured
if (aState != aLastState){
// If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
if (digitalRead(outputB) != aState) {
Serial.print("tourne a droite "+ mStep );
} else {
Serial.print("tourne a gauche "+ mStep );
if (sState != 0) {
mStep = mStep * 2 ;
} else {
mStep >= 100;
mStep == 1;
aLastState = aState; // Updates the previous state of the outputA with the current state

I want to control a stepping motor with an encoder, want to use the switch on the encoder to increase the number of step at every push of the switch.

here is the error code:

Arduino: 1.6.7 (Windows 10), Board: “Arduino Due (Native USB Port)”

rotary_to_step.ino:52: error: ‘aLastState’ does not name a type

aLastState = aState; // Updates the previous state of the outputA with the current state


rotary_to_step.ino:53: error: expected declaration before ‘}’ token



exit status 1
‘aLastState’ does not name a type

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

I am sure it is a dumb thing but just cant see where i goofed. I am a total noob, up to last night the last time I coded was in the 90’s when I had a BBS running in Basic.

Anyone can help?


1) Why on earth did you think this has anything to do with "Installation & Troubleshooting"? Doesn't sound "Programming Questions" two spots lower not wayyyyy more logical?

2) How did you manage to post it in complicated tables instead of in code tags like the forum rules state? See How to use the forum please.

3) 1.6.7 is already a pretty old version of the IDE. I never really used it so it was probably one of the versions with an annoying bug. 4) And for the error, press ctrl+T. Now your code is nicely formatted, can you spot the error? The second to last } closes the loop() :)

Check that your { and } are balanced.


get your self some commnunication skills, your lack of it make you look like a dumb ass that can code but thats it.. In life it is not what you know that is important, and not the way you show it. It is what you do with what you know that make you someone or not...


thanks for the answer it was just that and now the sketch compile.

one other thing, can the sysop here move that tread to the proper part of the forum, I did not clicked on the good section and I apologise if it cant be done you can delete it..

And I use table cause I am use to it. sorry if it cause so much problem to some user ;-)


get your self some communication skills, your lack of it make you look like a dumb ass

No it is you that has poor communication skills and it is you that is the dumb ass.

Who posted in the wrong section in the first place? If you can't understand the instructions of How to use this forum then how are you going to understand any reply you get?

OK so you made a mistake but don't compound it with bad manners.

Thanks for the compliment! ;) But I'm not the dumb ass who did not take the time to read anything and clearly posted in the wrong section. Because hé, the one on top is so convenient. I don't lack communication skills, I just lack the energy to use them on people who don't put any energy in writing a proper thread (as stated in How to use the forum). But hé, in the end I was a nice guy, I pointed you straight to the problem! Jobi-Wan simply reformulated that. 8)