| Electronics > Beginners |
| Stepper Motor control with an Arduino and Quadrature Optical Encoder question |
| (1/1) |
| bkukuk62:
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); } } |
| Blitzschnitzel:
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. |
| Navigation |
| Message Index |