多图详细教你怎样做一部Arduino小车
ed = 7;
int rled = 4;
int lmotor = 19;
int rmotor = 18;
int rdate = 0;
int ldate = 0;
int ledpin = 14;
int l = 0;
int r = 0;
int a = 0;
int b = 0;
int c = 0;
int e = 0;
void setup()
{
pinMode(lled,INPUT);
pinMode(rled,INPUT);
pinMode(lmotor,OUTPUT);
pinMode(rmotor,OUTPUT);
pinMode(ledpin,OUTPUT);
}
void run()
{
for(int i = 0;i 《 a;i ++)
{
digitalWrite(lmotor,HIGH);
delayMicroseconds(ldate);
digitalWrite(lmotor,LOW);
digitalWrite(rmotor,HIGH);
delayMicroseconds(rdate);
digitalWrite(rmotor,LOW);
delay(18);
}
}
void loop()
{
l = digitalRead(lled);
r = digitalRead(rled);
if ((l == HIGH) || (r == HIGH))
digitalWrite(ledpin,HIGH);
else
digitalWrite(ledpin,LOW);
if((l == HIGH)&&(r == HIGH))
{
while((l == HIGH)&&(r == HIGH))
{
l = digitalRead(lled);
r = digitalRead(rled);
}
}
else if(l == HIGH) //左边儿检测到黑线,左转
{
ldate = 1480;
rdate = 1630;
a = 10;
}
else if(r == HIGH) //右边儿检测到黑线,右转
{
ldate = 1350;
rdate = 1500;
a = 10;
}
else
{
ldate = 1300;
rdate = 1730;
a = 1;
}
run();
}
上图若干:
这个小车不算完,因为有太多的功能可供大家玩,比如我就装上了超声波和红外传感器,是不是挺萌的!
- 基于Arduino的会打招呼的超萌机器人(11-23)
- 工业环境中的树莓派(Raspberry Pi)和Arduino(09-12)
- 随时关注空气质量:工程师自制Arduino空气检测器(02-25)
- Wi-Fi遥控小车DIY教程:看高手如何改进(10-04)
- Arduino串口高级用法,你都掌握了吗?(06-16)
- 便捷好用的开发板不只有Arduino(03-27)