-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKXRControlPanel.ino
143 lines (114 loc) · 3.08 KB
/
KXRControlPanel.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
#define TOGGLE_BIT(button_state, bit) ((button_state) ^ (1 << bit))
// To Call: TOGGLE_BIT(0, 7)
const unsigned int checkInterval = 100;
/*
When reading in strings for OLED, config switches at the same time
if(emptry string) skip OLED
if that switch is hit, send "empty" to python and deal with it there
handle bitmasking in python instead
*/
// Stores previous button state for checking if there was an update
struct states{
bool sw_one = 0;
bool sw_two = 0;
bool sw_three = 0;
bool sw_four = 0;
bool sw_five = 0;
bool sw_six = 0;
bool sw_seven = 0;
bool sw_eight = 0;
bool sw_nine = 0;
bool sw_ten = 0;
bool bt_one = 0;
bool bt_two = 0;
bool bt_three = 0;
bool bt_four = 0;
bool bt_five = 0;
};
// Stores associated commands for sending to Python
// String stores "empty" if no function
struct commands{
String cmd_sw_one;
String cmd_sw_two;
String cmd_sw_three;
String cmd_sw_four;
String cmd_sw_five;
String cmd_sw_six;
String cmd_sw_seven;
String cmd_sw_eight;
String cmd_sw_nine;
String cmd_sw_ten;
String cmd_bt_one;
String cmd_bt_two;
String cmd_bt_three;
String cmd_bt_four;
String cmd_bt_five;
};
void setup(){
Serial.begin(115200);
// Wait until the serial becomes available
while(!Serial){
;
}
Serial.println("READY");
delay(1000);
configPanel();
}
void loop() {
checkButtons()
}
// Writes strings to OLEDs for associated switches
// Modifies switches based on function
void configPanel(){
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Initializes object
// do it again, name appropriately left to right 1-X
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// do it again
// Clears old stuff
display.display();
display.clearDisplay();
// Now do it again
// Gets the new stuff
commands.cmd_sw_one = Serial.readStringUntil('\n');
(commands.cmd_sw_one).trim();
if(commands.cmd_sw_one != "empty"){
// Puts the new stuff on there
display.setTextSize(2);
display.setTextColor(WHITE, BLACK);
display.setCursor(0,0);
display.print(commands.cmd_sw_one);
display.display();
}
// Now do it again
} // End configPanel()
void checkButtons(){
if(states.sw_one != digitalRead(sw_one_pin)){
Serial.println(command.cmd_sw_one);
}
// do it again
/*
if(switch one is hit)
ser.println(commands.cmd_sw_one);
*/
// See arduino change of state example
/*
15 if-statements
Also change the associated LED from Neopixel
} */
// This works, sends back b'This\r\n'
/*
String var = Serial.readString();
var.trim();
Serial.println(var);
*/