微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 硬件工程师文库 > 多图详细教你怎样做一部Arduino小车

多图详细教你怎样做一部Arduino小车

时间:06-24 来源:互联网 点击:

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();

  }

  上图若干:

  这个小车不算完,因为有太多的功能可供大家玩,比如我就装上了超声波和红外传感器,是不是挺萌的!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top