Created
June 23, 2018 20:00
-
-
Save chris-pws/0cd1b025fbe76cc32ef6b3dccde92145 to your computer and use it in GitHub Desktop.
Reads an 8 bit value (0 - 254) from the analog to digital converter and moves two stepper motors to a relative position within the motor's range (0 - 63). You could also use the Arduino map() function to translate the different ranges.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AccelStepper.h> | |
// Define a stepper and the pins it will use | |
//AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5 | |
AccelStepper xAxis(1, 4, 3); // pin 3 = step, pin 6 = direction | |
AccelStepper yAxis(1, 6, 5); // pin 3 = step, pin 6 = direction | |
#define Xpin A0 | |
#define Ypin A3 | |
void setup() | |
{ | |
// Change these to suit your stepper if you want | |
xAxis.setMaxSpeed(30); | |
yAxis.setMaxSpeed(30); | |
} | |
void loop() | |
{ | |
// Read new position | |
int Xpos = analogRead(Xpin) /4; | |
int Ypos = analogRead(Ypin) /4; | |
xAxis.moveTo(Xpos); | |
yAxis.moveTo(Ypos); | |
yAxis.runSpeedToPosition(); | |
xAxis.runSpeedToPosition(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment