码迷,mamicode.com
首页 > 其他好文 > 详细

光杆寻黑线

时间:2015-05-30 12:19:08      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:

int LA=14;
int LB=15;
int RA=16;
int RB=17;
int EN1=3;
int EN2=5;
const int LS=2;
const int RS=6;


void setup()
{
  pinMode(LA,OUTPUT);
  pinMode(LB,OUTPUT);
  pinMode(RA,OUTPUT);
  pinMode(RB,OUTPUT);
  pinMode(EN1,OUTPUT);
  pinMode(EN2,OUTPUT);
  pinMode(LS,INPUT);
  pinMode(RS,INPUT);
}
void loop()
{
  int LI=digitalRead(LS);
  int RI=digitalRead(RS);
  if (LI==LOW && RI==LOW) {forward(0.1);pause(0.2);}
   else if (LI==HIGH && RI==LOW) {right(0.25);pause(0.2);}
    else if (LI==LOW && RI==HIGH){left(0.25);pause(0.2);};
}


void forward(float a)
{
  analogWrite(EN1,150);
  digitalWrite(LA,HIGH);
  digitalWrite(LB,LOW);
  analogWrite(EN2,164);
  digitalWrite(RA,HIGH);
  digitalWrite(RB,LOW);
  delay(a*1000);
}


void left(float c)
{
  analogWrite(EN1,0);
  digitalWrite(LA,LOW);
  digitalWrite(LB,LOW);
  analogWrite(EN2,200);
  digitalWrite(RA,HIGH);
  digitalWrite(RB,LOW);
  delay(c*1000);
}


void right(float d)  
{
  analogWrite(EN1,200);
  digitalWrite(LA,HIGH);
  digitalWrite(LB,LOW);
  analogWrite(EN2,0);
  digitalWrite(RA,LOW);
  digitalWrite(RB,LOW);
  delay(d*1000);
}


void pause(float e)
{
  analogWrite(EN1,150);
  digitalWrite(LA,LOW);
  digitalWrite(LB,LOW);
  analogWrite(EN2,188);
  digitalWrite(RA,LOW);
  digitalWrite(RB,LOW);
  delay(e*1000);
}

光杆寻黑线

标签:

原文地址:http://blog.csdn.net/power_tile/article/details/46271575

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!