Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftWareSerial.h>
- #define M11 5
- #define M12 6
- #define M21 9
- #define M22 10
- SoftwareSerial bt(3, 4); // RX, TX
- int msg;
- void setup(){
- bt.begin(9600);
- pinMode(M11, OUTPUT);
- pinMode(M12, OUTPUT);
- pinMode(M21, OUTPUT);
- pinMode(M22, OUTPUT);
- }
- void loop(){
- if(bt.available() > 0){
- msg = bt.read();
- switch (msg){
- case 'F': forward(); break;
- case 'B': backward(); break;
- case 'L': left(); break;
- case 'R': right(); break;
- default: stop(); break;
- }
- }
- delay(10);
- }
- void forward(){
- digitalWrite(M11, HIGH);
- digitalWrite(M12, LOW);
- digitalWrite(M21, HIGH);
- digitalWrite(M21, LOW);
- }
- void forward(){
- digitalWrite(M11, HIGH);
- digitalWrite(M12, LOW);
- digitalWrite(M21, HIGH);
- digitalWrite(M21, LOW);
- }
- void backward(){
- digitalWrite(M11, LOW);
- digitalWrite(M12, HIGH);
- digitalWrite(M21, LOW);
- digitalWrite(M21, HIGH);
- }
- void left(){
- digitalWrite(M11, LOW);
- digitalWrite(M12, HIGH);
- digitalWrite(M21, HIGH);
- digitalWrite(M21, LOW);
- }
- void right(){
- digitalWrite(M11, HIGH);
- digitalWrite(M12, LOW);
- digitalWrite(M21, LOW);
- digitalWrite(M21, HIGH);
- }
- void stopp(){
- digitalWrite(M11, LOW);
- digitalWrite(M12, LOW);
- digitalWrite(M21, LOW);
- digitalWrite(M21, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement