1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| #include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11);
int back1 = 2; int front1 = 3; int back2 = 4; int front2 = 5; int back3 = 6; int front3 = 7; int back4 = 8; int front4 = 9; String command = "";
void initMoto() { digitalWrite(back1, HIGH); digitalWrite(front1, HIGH); digitalWrite(back2, HIGH); digitalWrite(front2, HIGH); digitalWrite(back3, HIGH); digitalWrite(front3, HIGH); digitalWrite(back4, HIGH); digitalWrite(front4, HIGH); }
void setup() { softSerial.begin(9600); Serial.begin(9600);
pinMode(back1, OUTPUT); pinMode(front1, OUTPUT); pinMode(back2, OUTPUT); pinMode(front2, OUTPUT); pinMode(back3, OUTPUT); pinMode(front3, OUTPUT); pinMode(back4, OUTPUT); pinMode(front4, OUTPUT);
initMoto(); }
void loop() { command = ""; while (softSerial.available() > 0) { command += char(softSerial.read()); delay(10); } if (command.length() > 0) { Serial.println(command); initMoto();
if (command.equals("front")) { digitalWrite(front1, LOW); digitalWrite(front2, LOW); digitalWrite(front3, LOW); digitalWrite(front4, LOW); } if (command.equals("back")) { digitalWrite(back1, LOW); digitalWrite(back2, LOW); digitalWrite(back3, LOW); digitalWrite(back4, LOW); } if (command.equals("left_back")) { digitalWrite(back1, LOW); digitalWrite(back4, LOW); } if (command.equals("right_front")) { digitalWrite(front1, LOW); digitalWrite(front4, LOW); } if (command.equals("left_front")) { digitalWrite(front2, LOW); digitalWrite(front3, LOW); } if (command.equals("right_back")) { digitalWrite(back2, LOW); digitalWrite(back3, LOW); } if (command.equals("left")) { digitalWrite(back1, LOW); digitalWrite(front2, LOW); digitalWrite(front3, LOW); digitalWrite(back4, LOW); } if (command.equals("right")) { digitalWrite(front1, LOW); digitalWrite(back2, LOW); digitalWrite(back3, LOW); digitalWrite(front4, LOW); } if (command.equals("left_circle")) { digitalWrite(front1, LOW); digitalWrite(front2, LOW); digitalWrite(back3, LOW); digitalWrite(back4, LOW); } if (command.equals("right_circle")) { digitalWrite(back1, LOW); digitalWrite(back2, LOW); digitalWrite(front3, LOW); digitalWrite(front4, LOW); } if (command.equals("stop")) { } } }
|