This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
86 lines (72 loc) · 2.2 KB
/
main.cpp
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
#include <Arduino.h>
const int PIN_A = 2;
const int PIN_B = 3;
const int PIN_X = 4;
const int PIN_Y = 5;
const int PIN_UP = 6;
const int PIN_LEFT = 7;
const int PIN_DOWN = 8;
const int PIN_RIGHT = 9;
const int PIN_L = 15;
const int PIN_R = 14;
const int PIN_START = 16;
const int PIN_SELECT = 10;
const int PIN_BUZZER = 18;
int main() {
init();
USBDevice.attach();
Serial.begin(9600);
pinMode(PIN_A, OUTPUT);
pinMode(PIN_B, OUTPUT);
pinMode(PIN_X, OUTPUT);
pinMode(PIN_Y, OUTPUT);
pinMode(PIN_UP, OUTPUT);
pinMode(PIN_LEFT, OUTPUT);
pinMode(PIN_DOWN, OUTPUT);
pinMode(PIN_RIGHT, OUTPUT);
pinMode(PIN_L, OUTPUT);
pinMode(PIN_R, OUTPUT);
pinMode(PIN_START, OUTPUT);
pinMode(PIN_SELECT, OUTPUT);
pinMode(PIN_BUZZER, OUTPUT);
int c = '.';
while (true) {
if (Serial.available()) {
c = Serial.read();
}
digitalWrite(PIN_A, c == 'A' ? LOW : HIGH);
digitalWrite(PIN_B, c == 'B' ? LOW : HIGH);
digitalWrite(PIN_X, c == 'X' ? LOW : HIGH);
digitalWrite(PIN_Y, c == 'Y' ? LOW : HIGH);
digitalWrite(PIN_UP, c == 'w' ? LOW : HIGH);
digitalWrite(PIN_LEFT, c == 'a' ? LOW : HIGH);
digitalWrite(PIN_DOWN, c == 's' ? LOW : HIGH);
digitalWrite(PIN_RIGHT, c == 'd' ? LOW : HIGH);
bool L_pressed = false;
bool R_pressed = false;
bool start_pressed = false;
bool select_pressed = false;
switch (c) {
case 'L':
L_pressed = true;
break;
case 'R':
R_pressed = true;
break;
case '[':
start_pressed = true;
break;
case ']':
select_pressed = true;
break;
case '*':
L_pressed = R_pressed = start_pressed = select_pressed = true;
break;
}
digitalWrite(PIN_L, L_pressed ? LOW : HIGH);
digitalWrite(PIN_R, R_pressed ? LOW : HIGH);
digitalWrite(PIN_START, start_pressed ? LOW : HIGH);
digitalWrite(PIN_SELECT, select_pressed ? LOW : HIGH);
digitalWrite(PIN_BUZZER, c == '!' ? HIGH : LOW);
}
}