/*
DIY small stage test
* Press the button(PBS1) connected to Arduino pin8 to run a stage foward.
* Press the button(PBS2) connected to Arduino pin9 to run a stage reverse.
*/
#define PBS1 8
#define PBS2 9
#define MOTOR1 2
#define MOTOR2 3
int s1=0,s2=0;
void setup() {
pinMode(PBS1, INPUT);
pinMode(PBS2, INPUT);
pinMode(MOTOR1 , OUTPUT);
pinMode(MOTOR2, OUTPUT);
}
void loop() {
s1=digitalRead(PBS1);
if(s1==0) { // While button is pressed...
digitalWrite(MOTOR1, LOW); //Motor direction:CW
digitalWrite(MOTOR2, HIGH); //Motor direction:CW
delay(50); //Debounce
}
else {
digitalWrite(MOTOR1, LOW); //stop
digitalWrite(MOTOR2, LOW); //stop
delay(50); //Debounce
}
s2=digitalRead(PBS2);
if(s2==0) { // While button is pressed...
digitalWrite(MOTOR1, HIGH); //Motor direction:CCW
digitalWrite(MOTOR2, LOW); //Motor direction:CCW
delay(50); //Debounce
}
else {
digitalWrite(MOTOR1, LOW); //stop
digitalWrite(MOTOR2, LOW); //stop
delay(50); //Debounce
}
}
Comments
Please log in or sign up to comment.