通过串口控制小车前后左右移动


#define Dong1 D6
#define Dong2 D7
#define Zhuan1 D4
#define Zhuan2 D5

void initL9110s()
{
  pinMode(Dong1,OUTPUT);
  pinMode(Dong2,OUTPUT);
  pinMode(Zhuan1 ,OUTPUT);
  pinMode(Zhuan2,OUTPUT);
 }
void qian()
{
   digitalWrite(Dong1,HIGH);
   digitalWrite(Dong2,LOW);
}
void hou()
{
   digitalWrite(Dong1,LOW);
   digitalWrite(Dong2,HIGH);
}
void ting()
{
  digitalWrite(Dong1,LOW);
  digitalWrite(Dong2,LOW);
  digitalWrite(Zhuan1,LOW);
  digitalWrite(Zhuan2,LOW);
 }
void zuo()
{
   digitalWrite(Zhuan1,HIGH);
   digitalWrite(Zhuan2,LOW);

}void you()
{
   digitalWrite(Zhuan1,LOW);
   digitalWrite(Zhuan2,HIGH);
}
void setup() {
  // put your setup code here, to run once:
 initL9110s();
Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
    char cmd;
     if (Serial.available()>0){
       cmd = Serial.read();
       switch(cmd){
         case'q':
           qian();
           break;
         case'h':
           hou();
           break;
         case'z':
           zuo();
           break;
          case'y':
           you();
           break;
           case's':
           ting();
           break;
       }
   }
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页