|
回復 8# ray41121
請試試改程式如下,看能不能轉快點:
---------------------------------------------
void setup()
{
Serial.begin(115200);
pinMode(2, INPUT);
pinMode(6, INPUT);
pinMode(motor1a,OUTPUT);
pinMode(motor2a,OUTPUT);
pinMode(e12,OUTPUT);
pinMode(motor3a,OUTPUT);
pinMode(motor4a,OUTPUT);
pinMode(e34,OUTPUT);
digitalWrite(e12,HIGH);
digitalWrite(e34,HIGH);
}
void loop()
{
{
int switchStatus = digitalRead(2);
digitalWrite(motor1a, switchStatus);
digitalWrite(motor3a, switchStatus);
Serial.println(switchStatus);
if (switchStatus == HIGH)
{
forwar();
delay(100);
return;
}
else {
digitalWrite(motor2a,LOW);
digitalWrite(motor4a,LOW);
}
}
{
int switchStatus = digitalRead(6);
digitalWrite(motor2a, switchStatus);
digitalWrite(motor4a, switchStatus);
Serial.println(switchStatus);
if (switchStatus == HIGH)
{
back();
delay(100);
return;
}
else {
digitalWrite(motor1a,LOW);
digitalWrite(motor3a,LOW);
}
}
return;
}
void forwar()
{
digitalWrite(motor1a,HIGH);
digitalWrite(motor2a,LOW);
digitalWrite(motor3a,HIGH);
digitalWrite(motor4a,LOW);
}
void back()
{
digitalWrite(motor1a,LOW);
digitalWrite(motor2a,HIGH);
digitalWrite(motor3a,LOW);
digitalWrite(motor4a,HIGH);
} |
|