Creating a stepCounter for stepper motors

Hi there,

I am new to physical computing and had a question about stepper motors counting the number of steps. Essentially what I’m aiming to do is to use the movement of the stepper motor to trigger certain messages on an LED Matrix, the movement is of course measured in the stepper motor’s steps.

Below is an idea of what I want the programme to do:

if (stepCounter == 10){
    //Print Message 1
  }

 if (stepCounter == 20){
    //Print Message 2
  }

However, I’m unsure of which functions will allow me to create a step counter that I can implement in my programme. Please let me know if you need anymore information, and thanks in advance for the support.

Alex

stepper motors will step when you tell them to step. So you know usually how many steps they’ve done.

There are libraries like accelStepper where you can give a target number of steps or arbitrary position to reach and the motor will step its way there at the speed you chose. Along the way you can ask where the stepper is (such as distanceToGo() or currentPosition())

if you don’t have an actual stepper but have a quadratic encoder connected to the shaft, then your code will receive “ticks” as the engine runs. The encoder library will give you the information you need by simply calling the read() method of the class and get a ‘number’ you can use in your tests

1 Like

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