Associate variable to another variable

I'm trying to assign the variable "counter" to "interval" so that when i turn the encoder, the value of "interval" also increases so that the speed of the stepper increases.

The code:

#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 200
#define outputA 6
#define outputB 7
int counter = 0;
int aState;
int aLastState;
int interval;

void setup() {
pinMode(outputA,INPUT);
pinMode(outputB,INPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);

Serial.begin (9600);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
}
void loop() {
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// 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) {
counter --;
} else {
counter ++;
}

interval = counter;

Serial.print("Time: ");
Serial.println(temps);
}

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

digitalWrite(dirPin, LOW);
for (int x = 0; x < 1 * stepsPerRevolution; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds((interval * 60000) / 4);
digitalWrite(stepPin, LOW);
delayMicroseconds((interval * 60000) / 4);
}

}

  temps == counter;

Could be. Could be.

  temps = counter;

Idahowalker:

  temps == counter;

Could be. Could be.

  temps = counter;

dosen't make a difference

mousse_raafat:
dosen't make a difference

Oh, but it does.

Please remember to use code tags when posting code.

mousse_raafat:
dosen't make a difference

Actually it does

interval == counter; is not the same as interval = counter;

One is a check to see if equal, one assigns counter to interval. If that change does not fix your problem, then you have another issue.

mousse_raafat:
dosen't make a difference

Please post your changed code.

Idahowalker:
Please post your changed code.

I cjanged it. Dosent make a difference, on the serial monitter i get 1 then 2 or 1 at random times.

Please repost your revised code.
In code tags

Dosent make a difference

I am willing to bet that it makes a difference. Whether it does what you want is another thing

aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // 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) { 
       counter --;
     } else {
       counter ++;
     }

Have you proved the above works with a few debug print statements, something about it looks to be wonky.

Also, by not using code tags, as it has been suggested, shows that you will not follow instructions. If you will not follow instructions to properly format your posted code than, which I find to be true, you will not follow instructions on proposed fixes.

Idahowalker:

aState = digitalRead(outputA); // Reads the "current" state of the outputA

// 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) {
      counter --;
    } else {
      counter ++;
    }




Have you proved the above works with a few debug print statements, something about it looks to be wonky.

Also, by not using code tags, as it has been suggested, shows that you will not follow instructions. If you will not follow instructions to properly format your posted code than, which I find to be true, you will not follow instructions on proposed fixes.

Im sorry Im new on this forum, I dont know how to format my code.

I dont know how to format my code.

Tools/Auto Format in the IDE or Ctrl+T from the keyboard is a good start

delayMicroseconds((interval * 60000) / 4);

The delay time parameter for delayMicroseconds() is pretty much limited limited to just over 16000 if you want predictable results.

You should change the code to use delay() with milliseconds, given the speeds you are looking at.