-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoscuelight.ino
More file actions
256 lines (239 loc) · 6.69 KB
/
oscuelight.ino
File metadata and controls
256 lines (239 loc) · 6.69 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#include <M5StickC.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BLEDevice.h> // To turn BLE off for powersafing
#include <OSCBundle.h> // for receiving OSC messages
#include <WiFiUdp.h> //UDP
const char* ssid = "THJ-Inspi"; //Credentials to register network defined by the SSID (Service Set IDentifier)
const char* password = "{,ulaS:HXV}m1*%VxG-mhje"; //and the second one a password if you wish to use it.
const char* hostid = "CUE2"; //Name it before you blame it
//IPAddress local_IP(192, 168, 100, 230);
//IPAddress gateway(192, 168, 100, 5);
//IPAddress subnet(255, 255, 255, 0);
//IPAddress primaryDNS(192, 168, 100, 5); // optional
//IPAddress secondaryDNS(8, 8, 4, 4); // optional
//Pinger pinger;
//UDP
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
const unsigned int localPort = 8000; // local port to listen for UDP packets(another device must send OSC messages to this port)
const unsigned int destPort = 9000; // remote port of the target device where we send OSC to
const int ledPin = 10; // LED-Pin
int OSCueLightID = 2; // OSCueLightID
String pathOSC = "/oscuelight/"; //OSC-String
char hierlang[42]; // buffer for OSC-String + ID
void setup(){
setCpuFrequencyMhz(80);
esp_bt_controller_disable();
//adc_power_release();
M5.begin();
pinMode (ledPin, OUTPUT);
// if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
// Serial.println("STA Failed to configure");
// }
WiFi.mode(WIFI_STA);
WiFi.hostname(hostid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
Udp.begin(localPort);
delay(1000);
M5.Lcd.setRotation(1);
M5.Lcd.fillScreen(GREEN);
M5.Lcd.setCursor(10, 10, 2);
M5.Lcd.print(WiFi.localIP());
delay(1000);
M5.Lcd.fillScreen(BLUE);
M5.Lcd.setCursor(10, 10, 2);
M5.Lcd.print(WiFi.localIP());
delay(1000);
M5.Lcd.fillScreen(RED);
M5.Lcd.setCursor(10, 10, 2);
M5.Lcd.print(WiFi.localIP());//NETWORK
//INSERT SETUP MENUE HIER
pathOSC = pathOSC + String(OSCueLightID);
M5.Lcd.setCursor(10, 30, 2);
M5.Lcd.print(pathOSC);
digitalWrite (ledPin, HIGH);
M5.Axp.ScreenBreath(7);
screenoff ();
}
void loop() {
OSCMessage msgIN;
int size;
if ((size = Udp.parsePacket()) > 0) {
while (size--)
msgIN.fill(Udp.read());
if (!msgIN.hasError()) {
pathOSC.toCharArray(hierlang,42);
msgIN.dispatch(strcat(hierlang, "/color"), colorscreen);
pathOSC.toCharArray(hierlang,42);
msgIN.dispatch(strcat(hierlang, "/write"), write);
pathOSC.toCharArray(hierlang,42);
msgIN.dispatch(strcat(hierlang, "/led"), led);
pathOSC.toCharArray(hierlang,42);
msgIN.dispatch(strcat(hierlang, "/clear"), clear);
pathOSC.toCharArray(hierlang,42);
msgIN.dispatch(strcat(hierlang, "/achtung"), achtung);
pathOSC.toCharArray(hierlang,42);
msgIN.dispatch(strcat(hierlang, "/go"), go);
pathOSC.toCharArray(hierlang,42);
msgIN.dispatch(strcat(hierlang, "/countdown"), countdown);
}
}
m5.update();
}
void colorscreen(OSCMessage &msg) {
screenon ();
M5.Axp.ScreenBreath(15);
char screencolor [16];
msg.getString(0, screencolor, 8);
if (strcmp(screencolor, "blue")==0){
M5.Lcd.fillScreen(BLUE);
M5.Lcd.setTextColor(WHITE, BLUE);
}
if (strcmp(screencolor, "red")==0){
M5.Lcd.fillScreen(RED);
M5.Lcd.setTextColor(WHITE, RED);
}
if (strcmp(screencolor, "green")==0){
M5.Lcd.fillScreen(GREEN);
M5.Lcd.setTextColor(WHITE, GREEN);
}
}
void write(OSCMessage &msg) {
if (msg.isInt(0)){
M5.Lcd.setRotation(0);
M5.Lcd.setCursor(5,5,2);
M5.Lcd.setTextSize(2);
M5.Lcd.print("CUE:");
M5.Lcd.setCursor(4,40,2);
M5.Lcd.setTextSize(4);
M5.Lcd.print(msg.getInt(0));
}
if (msg.isString(0)){
char payload [128];
M5.Lcd.setRotation(1);
M5.Lcd.setCursor(5,2,2);
M5.Lcd.setTextSize(1);
M5.Lcd.print("NACHRICHT:");
M5.Lcd.setCursor(2,20,2);
M5.Lcd.setTextSize(3);
msg.getString(0,payload,128);
M5.Lcd.print(payload);
}
}
void led(OSCMessage &msg) {
}
void clear(OSCMessage &msg) {
M5.Lcd.fillScreen(BLACK);
M5.Axp.ScreenBreath(7);
digitalWrite (ledPin, HIGH);
screenoff ();
}
void achtung(OSCMessage &msg) {
screenon ();
M5.Axp.ScreenBreath(15);
M5.Lcd.setTextColor(WHITE, GREEN);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.fillScreen(GREEN);
delay(500);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.fillScreen(GREEN);
delay(500);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.fillScreen(GREEN);
delay(500);
digitalWrite (ledPin, LOW);
if (msg.isInt(0)){
M5.Lcd.setRotation(0);
M5.Lcd.setCursor(5,5,2);
M5.Lcd.setTextSize(2);
M5.Lcd.print("CUE:");
M5.Lcd.setCursor(4,40,2);
M5.Lcd.setTextSize(4);
M5.Lcd.print(msg.getInt(0));
}
if (msg.isString(0)){
char payload [128];
M5.Lcd.setRotation(1);
M5.Lcd.setCursor(5,2,2);
M5.Lcd.setTextSize(1);
M5.Lcd.print("NACHRICHT:");
M5.Lcd.setCursor(5,20,2);
M5.Lcd.setTextSize(1);
msg.getString(0,payload,128);
M5.Lcd.print(payload);
}
}
void go(OSCMessage &msg) {
M5.Lcd.setTextColor(WHITE, RED);
digitalWrite (ledPin, HIGH);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(BLACK);
M5.Axp.ScreenBreath(7);
screenoff ();
}
void countdown(OSCMessage &msg) {
if (msg.isInt(0)){
M5.Axp.ScreenBreath(15);
screenon ();
digitalWrite (ledPin, LOW);
int number = msg.getInt(0);
M5.Lcd.setTextSize(6);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setRotation(1);
while (number > 0) {
M5.Lcd.setCursor(20,0,2);
M5.Lcd.fillScreen(BLACK);
if ( (number % 2) == 0){
M5.Lcd.invertDisplay(false);
M5.Lcd.print(number);
}
else {
M5.Lcd.invertDisplay(true);
M5.Lcd.print(number);
}
delay(1000);
number--;
}
if (number == 0) {
M5.Lcd.setTextColor(WHITE, RED);
digitalWrite (ledPin, HIGH);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(BLACK);
delay(500);
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(BLACK);
M5.Axp.ScreenBreath(7);
screenoff ();
}
}
}
void screenoff () {
Wire1.beginTransmission(0x34);
Wire1.write(0x12);
Wire1.write(0b01001011); // LDO2, aka OLED_VDD, off
Wire1.endTransmission();
}
void screenon () {
Wire1.beginTransmission(0x34);
Wire1.write(0x12);
Wire1.write(0x4d); // Enable LDO2, aka OLED_VDD
Wire1.endTransmission();
}