Skip to content

Instantly share code, notes, and snippets.

@henryyang42
Created June 11, 2014 14:09
Show Gist options
  • Save henryyang42/7245575ce162cfb5bd92 to your computer and use it in GitHub Desktop.
Save henryyang42/7245575ce162cfb5bd92 to your computer and use it in GitHub Desktop.
arduino step motor
#include <Stepper.h>
// number of steps on your motor
#define STEPS 64
char cmd;
//Stepper cw(STEPS, 8, 9, 10, 11);//clockwise
//Stepper ccw(STEPS, 8, 11, 10, 9);//counterclockwise
int delayTime = 1;
void setup()
{
//set motor speed
//cw.setSpeed(100);
//ccw.setSpeed(100);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);
}
int s[4][8] = {
{1,1,0,0,0,0,0,1},
{0,1,1,1,0,0,0,0},
{0,0,0,1,1,1,0,0},
{0,0,0,0,0,1,1,1},
};
void loop()
{
/* if(Serial.available())
{
cmd = Serial.read();
}
if(cmd == 'w') //press w for clockwise
{
cw.step(100);
}
else if(cmd == 'q')//press q for counterclockwise
{
ccw.step(100);
}*/
//cw.step(150);
for(int i = 0; i < 8; i+=1){
digitalWrite(8, s[0][i]);
digitalWrite(9,s[1][i]);
digitalWrite(10, s[2][i]);
digitalWrite(11,s[3][i]);
delay(delayTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment