是这样的,正转3圈,反转3圈,然后就停止勒,如何实现循环啊~~!
[code=cpp]int dirPin = 6;
int stepperPin = 5;
int switch1 = 14;
int switch2 = 15;
int value;
void setup() {
pinMode(dirPin, OUTPUT);
pinMode(stepperPin, OUTPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
}
void step(boolean dir,int steps){
digitalWrite(dirPin,dir);
for(int i=0; i < steps; i ++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepperPin, LOW);
delayMicroseconds(500);
// speed control
delayMicroseconds(100);
}
}
void loop(){
value = digitalRead(switch1);
if (HIGH == value) {
step(true,1600 * 3);
}
value = digitalRead(switch2);
if (HIGH == value) {
step(false,1600 * 3);
}
}
[/code]
这是程序 |