-
Notifications
You must be signed in to change notification settings - Fork 5
/
Bot.ino
71 lines (63 loc) · 1.31 KB
/
Bot.ino
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
int led = 2;
int l1 = 6;
int r1 = 5;
int l2 = 4;
int r2 = 3;
char cmd[100];
int cmdIndex;
void movement() {
if(strcmp(cmd, "f")==0) {
digitalWrite(l1, HIGH);
digitalWrite(r1, HIGH);
digitalWrite(l2, LOW);
digitalWrite(r2, LOW);
}
if(strcmp(cmd, "b")==0) {
digitalWrite(l1, LOW);
digitalWrite(r1, LOW);
digitalWrite(l2, HIGH);
digitalWrite(r2, HIGH);
}
if(strcmp(cmd, "l")==0) {
digitalWrite(l1, LOW);
digitalWrite(r1, HIGH);
digitalWrite(l2, HIGH);
digitalWrite(r2, LOW);
}
if(strcmp(cmd, "r")==0) {
digitalWrite(l1, HIGH);
digitalWrite(r1, LOW);
digitalWrite(l2, LOW);
digitalWrite(r2, HIGH);
}
if((cmdIndex==0)||(strcmp(cmd,"s")==0)) {
digitalWrite(l1, LOW);
digitalWrite(r1, LOW);
digitalWrite(l2, LOW);
digitalWrite(r2, LOW);
}
}
void setup() {
delay(500);
Serial.begin(9600);
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
cmdIndex=0;
}
void loop() {
if(Serial.available()) {
char c = (char)Serial.read();
if(c=='\n') {
cmd[cmdIndex] = 0;
//exeCmd();
movement();
cmdIndex=0;
}
else {
cmd[cmdIndex]=c;
if(cmdIndex<99) cmdIndex++;
}
}
}