|
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
}
void loop()
{
int FORW=digitalRead(A1);
int BACK=digitalRead(A2);
int LEFT=digitalRead(A3);
int RIGHT=digitalRead(A4);
if(FORW==0,BACK==0,LEFT==0,RIGHT==0)
{
analogWrite(3,0);
analogWrite(5,0);
}
delay(300);
if(FORW==1)
{digitalWrite(2,LOW);
digitalWrite(4,HIGH);
analogWrite(3,200);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
analogWrite(5,200);
}
delay(300);
if(BACK==1)
{digitalWrite(2,HIGH);
digitalWrite(4,LOW);
analogWrite(3,200);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
analogWrite(5,200);
}
delay(300);
if(LEFT==1)
{digitalWrite(2,HIGH);
digitalWrite(4,LOW);
analogWrite(3,200);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
analogWrite(5,200);
}
delay(300);
if(RIGHT==1)
{digitalWrite(2,LOW);
digitalWrite(4,HIGH);
analogWrite(3,200);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
analogWrite(5,200);
}
delay(300);
}
这是我写的程序,现在车前进时一走一停顿,左转和右转也是一走一停顿,程序应该怎么写?
还有后退的时候,是正常的,这是为什么?是因为delay语句吗?
遥控器是一个四键的遥控器。
谢谢高手和大神们! |
|