[cce_cpp theme="blackboard"]
#include <Servo.h>
#include <SoftwareSerial.h>
Servo myservo;//Build an object for steering engine
// It can control 8 steering engines at max with Servo.
#define LED_D36 36
#define LED_D35 35
#define LED_D44 44
int pos = 90;
void setup()
{
Serial.begin(115200);
Serial2.begin(115200);
myservo.attach(10); // The steering engine is controlled by pin 10.
pinMode(LED_D44, OUTPUT);
pinMode(LED_D36, OUTPUT);
pinMode(LED_D35, OUTPUT);
}
void loop()
{
char lan;
if(Serial2.available())
{
lan=Serial2.read();
Serial.println(lan);
}
if(lan==4)
{
digitalWrite(LED_D36, HIGH);
digitalWrite(LED_D35, LOW);
digitalWrite(LED_D44, HIGH);
Serial.println("hou");
}
if(lan==3)
{
digitalWrite(LED_D36, LOW);
digitalWrite(LED_D35, LOW);
digitalWrite(LED_D44, HIGH);
Serial.println("ting");
}
if(lan==5)
{
digitalWrite(LED_D36, LOW);
digitalWrite(LED_D35, HIGH);
digitalWrite(LED_D44, HIGH);
Serial.println("qian");
}
if(lan==9)
{
pos = 90; // Move directly
myservo.write(pos); //Set steering engine rotate angle.
delay(1); // Wait 1ms for steering engine arrives the designated area.
Serial.println("zhi");
}
if(lan==8)
{
pos = 70; //Turn left
myservo.write(pos); // Set steering engine rotate angle.
delay(1); // Wait 1ms for steering engine arrives the designated area.
Serial.println("zuo");
}
if(lan==7)
{
pos = 110; //Turn right
myservo.write(pos); // Set steering engine rotate angle.
delay(1); // Wait 1ms for steering engine arrives the designated area.
Serial.println("you");
}
}
[/cce_cpp]