Arduino + Unipolar Stepper Motor + ULN2004A + Bipolar Stepper Motor + L293DNE + 2 Potentiometers


Arduino Code

#include <Stepper.h>
#define biSTEPS 200
#define uniSTEPS 400
int last_verti, curr_verti, last_horiz, curr_horiz;

Stepper bi_stepper(biSTEPS, 7, 6, 5, 4);
Stepper uni_stepper(uniSTEPS, 8, 9, 10, 11);

void setup(){
Serial.begin(9600);
bi_stepper.setSpeed(15);
uni_stepper.setSpeed(15);
}

void loop(){
sweepVertical();
sweepHorizontal();
}

void sweepVertical(){
bi_stepper.step(10);
bi_stepper.step(-10);
delay(100);
}

void sweepHorizontal(){
uni_stepper.step(20);
uni_stepper.step(-20);
delay(100);
}

void controlVertical(){
curr_verti = analogRead(0);
if(abs(curr_verti - last_verti) > 20) blinkLed();
else bi_stepper.step(curr_verti-last_verti);
last_verti = curr_verti;
delay(100);
}

void controlHorizontal(){
curr_horiz = analogRead(1);
if(abs(curr_horiz - last_horiz) > 20) blinkLed();
else uni_stepper.step(curr_horiz-last_horiz);
last_horiz = curr_horiz;
delay(100);
}

void blinkLed(){
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
}

No comments:

Post a Comment