-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_arduino.pde
55 lines (52 loc) · 1.69 KB
/
master_arduino.pde
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
// Pin configuration:
// Right button - Brown Wire
int RIGHT_PIN = 13;
// Left button - Green Wire
int LEFT_PIN = 12;
// Up button - White Wire
int UP_PIN = 11;
// Down button - Blue Wire
int DOWN_PIN = 10;
// A button - Orange Wire
int A_PIN = 9;
// B button - Gray Wire
int B_PIN = 8;
// last byte read from serial port
int readByte = 0;
void setup()
{
Serial.begin(9600);
// set one output pin for each possible command
// set initial state as inactive, that is, HIGH output
pinMode(LEFT_PIN, OUTPUT); digitalWrite(LEFT_PIN, HIGH);
pinMode(RIGHT_PIN, OUTPUT); digitalWrite(RIGHT_PIN, HIGH);
pinMode(DOWN_PIN, OUTPUT); digitalWrite(DOWN_PIN, HIGH);
pinMode(UP_PIN, OUTPUT); digitalWrite(UP_PIN, HIGH);
pinMode(A_PIN, OUTPUT); digitalWrite(A_PIN, HIGH);
pinMode(B_PIN, OUTPUT); digitalWrite(B_PIN, HIGH);
}
void loop()
{
// since the voltage drops to zero when a button is pressed,
// in order to send "A button" command, its wire output should be
// set to low.
if (Serial.available() > 0)
{
readByte = Serial.read();
switch (readByte)
{
case 1: digitalWrite(LEFT_PIN, LOW); break;
case 2: digitalWrite(LEFT_PIN, HIGH); break;
case 3: digitalWrite(RIGHT_PIN, LOW); break;
case 4: digitalWrite(RIGHT_PIN, HIGH); break;
case 5: digitalWrite(DOWN_PIN, LOW); break;
case 6: digitalWrite(DOWN_PIN, HIGH); break;
case 7: digitalWrite(UP_PIN, LOW); break;
case 8: digitalWrite(UP_PIN, HIGH); break;
case 9: digitalWrite(A_PIN, LOW); break;
case 10: digitalWrite(A_PIN, HIGH); break;
case 11: digitalWrite(B_PIN, LOW); break;
case 12: digitalWrite(B_PIN, HIGH); break;
}
}
}