|
楼主 |
发表于 2013-4-6 07:58
|
显示全部楼层
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);
}
void loop()
{
int FORW=digitalRead(10);
int BACK=digitalRead(11);
int LEFT=digitalRead(12);
int RIGHT=digitalRead(13);
if(FORW==1)
{digitalWrite(2,0);
digitalWrite(4,1);
analogWrite(3,250);
digitalWrite(7,0);
digitalWrite(8,1);
analogWrite(5,250);
}
else if(BACK==1)
{digitalWrite(2,1);
digitalWrite(4,0);
analogWrite(3,250);
digitalWrite(7,1);
digitalWrite(8,0);
analogWrite(5,250);
}
else if(LEFT==1)
{digitalWrite(2,0);
digitalWrite(4,1);
analogWrite(3,250);
digitalWrite(7,1);
digitalWrite(8,0);
analogWrite(5,250);
}
else if(RIGHT==1)
{digitalWrite(2,1);
digitalWrite(4,0);
analogWrite(3,250);
digitalWrite(7,0);
digitalWrite(8,1);
analogWrite(5,250);
}
else
{digitalWrite(2,0);
digitalWrite(4,0);
analogWrite(3,0);
digitalWrite(7,0);
digitalWrite(8,0);
analogWrite(5,0);
}
又奋斗一天,终于搞定,原来if语句和if else还是有区别的!
下面继续努力,想在车上加3或4自由度的机械手,再加摄像头之类的扩展,继续学习!
谢谢回复的朋友和论坛,对我的帮助! |
|