-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp32ArtNetServer.ino
122 lines (106 loc) · 2.89 KB
/
esp32ArtNetServer.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
/*
This example will transmit a universe via Art-Net into the Network.
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/
#include <ArtnetWifi.h>
#include <Arduino.h>
#include <map>
//Wifi settings
const char* ssid = "Art-Net"; // CHANGE FOR YOUR SETUP
const char* password = "esp32artnetAP"; // CHANGE FOR YOUR SETUP
// Artnet settings
ArtnetWifi artnet0;
ArtnetWifi artnet1;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
const char host0[] = "2.0.0.2"; // CHANGE FOR YOUR SETUP your destination
const char host1[] = "2.0.0.3"; // CHANGE FOR YOUR SETUP your destination
struct RGB {
byte r;
byte g;
byte b;
};
RGB defaultColours[] = {
{255,0,0},
{0,255,0},
{0,0,255},
{255, 255, 0},
{0,255, 255}
};
RGB currentColour = {0,0,0};
bool bChangeColour = true;
int artnetRefreshIntervalMS = 40;
int artnetLastRefreshTime = millis();
int microphoneInterruptPin = 4;
void IRAM_ATTR isr() {
bChangeColour = true;
}
// connect to wifi – returns true if successful or false if not
boolean ConnectWifi(void)
{
boolean state = true;
int i = 0;
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20){
state = false;
break;
}
i++;
}
if (state){
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
void changeColour() {
currentColour = defaultColours[random(sizeof(defaultColours))];
for (int i=0; i<61; i++) {
artnet0.setByte(i*3+0, currentColour.r);
artnet0.setByte(i*3+1, currentColour.g);
artnet0.setByte(i*3+2, currentColour.b);
}
for (int i=0; i<30; i++) {
artnet1.setByte(i*3+0, currentColour.r);
artnet1.setByte(i*3+1, currentColour.g);
artnet1.setByte(i*3+2, currentColour.b);
}
}
void setup()
{
Serial.begin(115200);
pinMode(microphoneInterruptPin, INPUT);
attachInterrupt(microphoneInterruptPin, isr, RISING);
ConnectWifi();
artnet0.begin(host0);
artnet0.setLength(3*61);
artnet0.setUniverse(startUniverse);
artnet1.begin(host1);
artnet1.setLength(3*30);
artnet1.setUniverse(startUniverse);
}
void loop() {
if (bChangeColour) {
Serial.println("Changing Colour");
changeColour();
bChangeColour = false;
}
if (millis() - artnetLastRefreshTime >= artnetRefreshIntervalMS) {
artnet1.write();
artnet0.write();
artnetLastRefreshTime = millis();
}
delay(1);
}