-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino-cta-tracker.ino
126 lines (106 loc) · 2.37 KB
/
arduino-cta-tracker.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
115
116
117
118
119
120
121
122
123
124
125
126
#include "Arduino.h"
#include "Keypad.h"
#include <LiquidCrystal.h>
#include <Process.h>
#include "constants.h"
LiquidCrystal lcd(LCD_PINS);
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {KEYPAD_ROW_PINS}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {KEYPAD_COL_PINS}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(LCD_BACKLIGHT_PIN, OUTPUT);
lcd.begin(16, 2);
digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
lcd.print(START_MESSAGE);
Bridge.begin();
digitalWrite(LCD_BACKLIGHT_PIN, LOW);
lcd.clear();
}
void loop(){
char key = keypad.getKey();
if (key){
digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
String label = getLabel(key);
lcd.print(label);
String command = getCommand(key);
runCommandAndPrint(command);
delay(SHOW_RESULTS_DELAY);
digitalWrite(LCD_BACKLIGHT_PIN, LOW);
lcd.clear();
}
}
void runCommandAndPrint(String command) {
Process p;
p.runShellCommand(command);
lcd.setCursor(0,1);
while (p.available()>0) {
char c = p.read();
if (c != '\n') {
lcd.write(c);
}
}
}
String getLabel(char key) {
switch ( key ) {
case '1':
return KEY_1_LABEL;
case '2':
return KEY_2_LABEL;
case '3':
return KEY_3_LABEL;
case '4':
return KEY_4_LABEL;
case '5':
return KEY_5_LABEL;
case '6':
return KEY_6_LABEL;
case '7':
return KEY_7_LABEL;
case '8':
return KEY_8_LABEL;
case '9':
return KEY_9_LABEL;
case '*':
return KEY_STAR_LABEL;
case '0':
return KEY_0_LABEL;
case '#':
return KEY_POUND_LABEL;
}
}
String getCommand(char key) {
switch ( key ) {
case '1':
return KEY_1_COMMAND;
case '2':
return KEY_2_COMMAND;
case '3':
return KEY_3_COMMAND;
case '4':
return KEY_4_COMMAND;
case '5':
return KEY_5_COMMAND;
case '6':
return KEY_6_COMMAND;
case '7':
return KEY_7_COMMAND;
case '8':
return KEY_8_COMMAND;
case '9':
return KEY_9_COMMAND;
case '*':
return KEY_STAR_COMMAND;
case '0':
return KEY_0_COMMAND;
case '#':
return KEY_POUND_COMMAND;
}
}