Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int in1 = 2;
- const int in2 = 4;
- const int in3 = 6;
- const int in4 = 8;
- const char stepperConfig[] = {
- 1,0,0,0,
- 1,1,0,0,
- 0,1,0,0,
- 0,1,1,0,
- 0,0,1,0,
- 0,0,1,1,
- 0,0,0,1,
- 1,0,0,1
- };
- int stepDelay = 1000;
- int angle = 360;
- void setup() {
- pinMode(in1, OUTPUT);
- pinMode(in2, OUTPUT);
- pinMode(in3, OUTPUT);
- pinMode(in4, OUTPUT);
- }
- void loop() {
- int angleSteps = angle*64/45;
- for(int i=0;i<angleSteps;i++){
- rotateCW();
- }
- delay(500);
- for(int i=0;i<angleSteps;i++){
- rotateCCW();
- }
- delay(500);
- }
- void doMotorStep(unsigned char stepNumber){
- unsigned char stepIndex = (stepNumber % 8) * 4;
- digitalWrite(in1, (stepperConfig[stepIndex]) ? HIGH : LOW);
- digitalWrite(in2, (stepperConfig[stepIndex+1]) ? HIGH : LOW);
- digitalWrite(in3, (stepperConfig[stepIndex+2]) ? HIGH : LOW);
- digitalWrite(in4, (stepperConfig[stepIndex+3]) ? HIGH : LOW);
- delayMicroseconds(stepDelay);
- }
- void rotateCW() {
- for (char i=0; i<8; i++){
- doMotorStep(i);
- }
- }
- void rotateCCW() {
- for (char i=7; i>=0; i--){
- doMotorStep(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment