Author Topic: Stepper Motor control with an Arduino and Quadrature Optical Encoder question  (Read 778 times)

0 Members and 1 Guest are viewing this topic.

Offline bkukuk62Topic starter

  • Newbie
  • Posts: 7
  • Country: us
I am currently using the following code that rotates a Nema 17 Stepper motor with a Quadrature Optical Encoder.

Is it possible to have another loop that is triggered by a button press to rotate the Stepper Motor clockwise at a certain speed for 10 full rotations or until another button is pressed to put it back in the original mode?

Here is the code I am currently using.


 #include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution for your motor

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

int stepCount = 0;  // number of steps the motor has taken

void setup() {
  // nothing to do inside the setup
}

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
}
« Last Edit: September 14, 2019, 10:35:47 pm by bkukuk62 »
 

Offline Blitzschnitzel

  • Regular Contributor
  • *
  • Posts: 64
  • Country: de
Is analogRead(A0) a potentiometer?
I am not absolutely sure what you want it to do but maybe something like this?
if (buttonA == HIGH){
   while(ButtonB == LOW){
      Rotate 10 clockwise;
}}
In the right syntax off course.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf