Try to make a control for a control to stop a Stepper Motor from button input

I tried to make a program to control a stepper motor with A4988 module to stop after a button have been pressed for a certain times (in my case is 25 times). but idk why it wont stop. plz help.

byte PushA = 11;
byte stepPin = 10;
byte dirPin = 9;
byte sleepPin = 8;
int Counter = 0;
int customDelay,customDelayMapped; // Defines variables

void setup(){
  Serial.begin(115200);
  pinMode(PushA, INPUT);
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  digitalWrite(dirPin,HIGH);
  pinMode(5, INPUT_PULLUP);
}

void loop() {

  
  customDelayMapped = speedUp();
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);

  if (digitalRead(PushA)){
    Counter++;
    delay(200);
    Serial.println("Nilai Counter : ");
    Serial.println(Counter);
  }

  if(Counter = 25){
    digitalWrite(sleepPin, LOW);
  }
}


int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,4000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
}

Oops.

Use (Counter == 25) not (Counter = 25)

ah gee thx XD

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