Last active
May 11, 2017 16:53
-
-
Save renatoargh/818874b8d1d37b5c2abc to your computer and use it in GitHub Desktop.
Controlling stepper motor w/ arduino and joystick https://www.youtube.com/watch?v=locew337i4M
This file contains hidden or 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
// Subscribe to Renatuino Pi channel on YouTube! | |
// See it here; https://www.youtube.com/watch?v=locew337i4M | |
int DIRECTION_X = A0; | |
int COIL1_A = 4; | |
int COIL1_B = 5; | |
int COIL2_A = 6; | |
int COIL2_B = 7; | |
int DELAY = 2; | |
void setup() { | |
pinMode(COIL1_A, OUTPUT); | |
pinMode(COIL2_B, OUTPUT); | |
pinMode(COIL1_A, OUTPUT); | |
pinMode(COIL2_B, OUTPUT); | |
} | |
void setStep(int coil1a, int coil1b, int coil2a, int coil2b) { | |
digitalWrite(COIL1_A, coil1a); | |
digitalWrite(COIL1_B, coil1b); | |
digitalWrite(COIL2_A, coil2a); | |
digitalWrite(COIL2_B, coil2b); | |
delay(DELAY); | |
} | |
void forwards() { | |
setStep(HIGH, LOW, HIGH, LOW); | |
setStep(LOW, HIGH, HIGH, LOW); | |
setStep(LOW, HIGH, LOW, HIGH); | |
setStep(HIGH, LOW, LOW, HIGH); | |
} | |
void backwards() { | |
setStep(HIGH, LOW, LOW, HIGH); | |
setStep(LOW, HIGH, LOW, HIGH); | |
setStep(LOW, HIGH, HIGH, LOW); | |
setStep(HIGH, LOW, HIGH, LOW); | |
} | |
void loop() { | |
int directionX = analogRead(DIRECTION_X); | |
if(directionX == 0) { | |
forwards(); | |
} | |
if(directionX >= 1000) { | |
backwards(); | |
} | |
delay(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello I have your set up here but I like to slow down my stepper motor 17 is going to fast for my mag loop antenna with variable capacitors
can you help ,