-
Notifications
You must be signed in to change notification settings - Fork 6
/
pixelation_bot.ino
114 lines (94 loc) · 2.17 KB
/
pixelation_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
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
110
111
112
113
114
int R_MOTOR_POS = 8;
int R_MOTOR_NEG = 9;
int L_MOTOR_POS = 11;
int L_MOTOR_NEG = 12;
int delay_forward = 125;
int delay_turn = 125;
void setup()
{
pinMode(L_MOTOR_POS, OUTPUT);
pinMode(L_MOTOR_NEG, OUTPUT);
pinMode(R_MOTOR_POS, OUTPUT);
pinMode(R_MOTOR_NEG, OUTPUT);
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,LOW);
Serial.begin(9600);
}
void stop() {
digitalWrite(R_MOTOR_POS,HIGH);
digitalWrite(R_MOTOR_NEG,HIGH);
digitalWrite(L_MOTOR_POS,HIGH);
digitalWrite(L_MOTOR_NEG,HIGH);
}
void forward() {
digitalWrite(R_MOTOR_POS,HIGH);
digitalWrite(R_MOTOR_NEG,LOW);
digitalWrite(L_MOTOR_POS,LOW);
digitalWrite(L_MOTOR_NEG,HIGH);
delay(delay_forward);
stop();
}
void right() {
digitalWrite(R_MOTOR_POS,LOW);
digitalWrite(R_MOTOR_NEG,LOW);
digitalWrite(L_MOTOR_POS,LOW);
digitalWrite(L_MOTOR_NEG,HIGH);
delay(delay_turn);
stop();
}
void left() {
digitalWrite(R_MOTOR_POS,HIGH);
digitalWrite(R_MOTOR_NEG,LOW);
digitalWrite(L_MOTOR_POS,LOW);
digitalWrite(L_MOTOR_NEG,LOW);
delay(delay_turn);
stop();
}
void back() {
digitalWrite(R_MOTOR_POS,LOW);
digitalWrite(R_MOTOR_NEG,HIGH);
digitalWrite(L_MOTOR_POS,HIGH);
digitalWrite(L_MOTOR_NEG,LOW);
delay(delay_forward);
stop();
}
void blink() {
digitalWrite(LED_BUILTIN,HIGH);
delay(1000);
digitalWrite(LED_BUILTIN,LOW);
}
void loop()
{
int incomingByte = 0;
if(Serial.available() > 0) {
incomingByte = Serial.read();
if(incomingByte == 'W') {
forward();
Serial.println("forward");
delay(200);
stop();
}
if(incomingByte == 'A') {
left();
Serial.println("left");
delay(200);
stop();
}
if(incomingByte == 'D') {
right();
Serial.println("right");
delay(200);
stop();
}
if(incomingByte == 'S') {
back();
Serial.println("back");
delay(500);
stop();
}
if(incomingByte == 'B') {
blink();
Serial.println("blink");
}
}
}