Code
[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]
Share this post
About the Author

Admin
How to Send Micro:bit Data to ThingSpeak IoT Platform
January 11, 2018
VC0706 Camera Module DIY Guide
December 18, 2014
nRF24L01 Module Demo for Arduino
May 6, 2011
Topics
- Curriculum
- Course
- Micro bit supplier
- Wholesale Suppliers
- Micro bit tutorial
- Micro bit classroom pack
- Mcorbit Environment Monitoring
- Temperature-controlled
- Motor
- Fan
- TPBot car
- TPBot
- Micro:bit car
- AI Lens
- Micor:bit AI Lens
- Micro:bit LEDs
- BBC micro:bit
- Micro:bit Manipulator
- Wukong board
- Cutebot
- Micro:bit Motorcycle
- Nezha breakout
- Micro:bit DIY
- 360° servos
- AI Lens
- Retro Arcade
- Ecode
- PlanetX
- Microbit programming
- Your:bit
- Do your:bit
- IoT:bit
- Octopus
- Rainbow LED Ring
- Joystick:bit
- Wonder Building Kit
- Sensor:bit
- Downie
- Wenjie
- Laser Engraver Tutorial
Tags
Micro:bit
DIY
micro bit course
micro bit curriculum
micro bit supplier
micro:bit supplier
micro bit classroom pack
micro:bit classroom pack
micro bit tutorial
micro:bit tutorial
TPBot
micro:bit car
AI Lens
micro:bit AI Lens
microbit gyroscope
Micro:bit LEDs
BBC micro:bit
Micro:bit Manipulator
Wukong board
Cutebot
micro:bit Motorcycle
nezha breakout
micro:bit music
360° servos
AI Lens
Retro Arcade
ecode
PlanetX
sonar:bit
Microbit programming
your:bit
do your:bit
IoT:bit
Octopus
Rainbow LED Ring
Joystick:bit
Wonder Building Kit
Laser Engraver
Laser Engraving Machine
Wish List
Comments