-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWiFlyCtrl.pde
More file actions
69 lines (59 loc) · 1.24 KB
/
WiFlyCtrl.pde
File metadata and controls
69 lines (59 loc) · 1.24 KB
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
#include <Servo.h>
#define LENGTH 1
int rxBuffer[128];
int rxIndex = 0;
Servo frontServo;
Servo leftServo;
Servo rightServo;
void setup() {
Serial.begin(9600);
//Attach servos to digital IO pins.
frontServo.attach(11);
leftServo.attach(9);
rightServo.attach(10);
//Set servers to 0.
frontServo.write(90);
leftServo.write(90);
rightServo.write(90);
}
void loop () {
if (Serial.available() > 0) {
rxBuffer[rxIndex++] = Serial.read();
if (rxIndex == LENGTH) {
//Serial.print("Byte received: ");
//Serial.println(rxBuffer[0]);
if (rxBuffer[0] == 48) {
forward();
} else if (rxBuffer[0] == 49) {
right();
} else if (rxBuffer[0] == 50) {
reverse();
} else if (rxBuffer[0] == 51) {
left();
} else if (rxBuffer[0] == 52) {
stopAll();
}
rxIndex = 0;
}
}
}
void forward () {
leftServo.write(135);
rightServo.write(35);
};
void right () {
leftServo.write(135);
rightServo.write(90);
}
void reverse () {
leftServo.write(35);
rightServo.write(135);
}
void left () {
leftServo.write(90);
rightServo.write(35);
}
void stopAll () {
leftServo.write(90);
rightServo.write(90);
}