-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrainControl
More file actions
127 lines (105 loc) · 2.03 KB
/
TrainControl
File metadata and controls
127 lines (105 loc) · 2.03 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
// Train Controller Program
// Dennis Toy Jr
// March 25, 2016
void setup() {
Keyboard.begin();
//Control Inputs
//Main Train Functions
pinMode(8, INPUT_PULLUP); //Switch
pinMode(9, INPUT_PULLUP); //Horn
pinMode(11,INPUT_PULLUP); //Sander
pinMode(7, INPUT_PULLUP);//Reverser Forward
pinMode(6, INPUT_PULLUP);//Reverser Backwards
pinMode(10, INPUT_PULLUP);//Emergency Brake
pinMode(12, INPUT_PULLUP);//Bell
pinMode(5, INPUT_PULLUP);// Increase Brake
pinMode(4, INPUT_PULLUP);// Decrease Brake
pinMode(2, INPUT_PULLUP);// Increase Throttle
pinMode(3, INPUT_PULLUP);// Decrease Throttle
}
void loop() {
// Main Train Functions
int buttonState8 = digitalRead(8);
int buttonState9 = digitalRead(9);
int buttonState11 = digitalRead(11);
int buttonState12 = digitalRead(12);
int buttonState7 = digitalRead(7);
int buttonState6 = digitalRead(6);
int buttonState10 = digitalRead(10);
//Brake and Throttle Control
//Brake
int buttonState5 = digitalRead(5);
int buttonState4 = digitalRead(4);
//Throttle
int buttonState2 = digitalRead(2);
int buttonState3 = digitalRead(3);
// Main Functions
//Common Train Controls
if (buttonState8 == LOW){
Keyboard.press(71);
}
else {
Keyboard.release(71);
}
if (buttonState9 == LOW) {
Keyboard.press(32);
}
else{
Keyboard.release(32);
}
// Fire Button = Left Ctrl key
if(buttonState11 == LOW) {
Keyboard.press(88);
}
else{
Keyboard.release(88);
}
if(buttonState12 == LOW) {
Keyboard.press(66);
}
else{
Keyboard.release(66);
}
if(buttonState7 == LOW) {
Keyboard.press(83);
}
else{
Keyboard.release(83);
}
if(buttonState6 == LOW) {
Keyboard.press(87);
}
else{
Keyboard.release(87);
}
if(buttonState10 == LOW) {
Keyboard.press(178);
}
else{
Keyboard.release(178);
}
if(buttonState2 == LOW) {
Keyboard.press(68);
}
else{
Keyboard.release(68);
}
if(buttonState3 == LOW) {
Keyboard.press(65);
}
else{
Keyboard.release(65);
}
if(buttonState5 == LOW) {
Keyboard.press(59);
}
else{
Keyboard.release(59);
}
if (buttonState4 == LOW) {
Keyboard.press(44);
}
else{
Keyboard.release(44);
}
}