2020-12-01 19:40:58 -05:00
|
|
|
/*
|
|
|
|
WiFlash_esp32 - Concept & electronics: Phil Abeyta
|
|
|
|
- System design & firmware: Kevin Matz
|
2020-12-04 14:57:57 -05:00
|
|
|
|
|
|
|
Uses a GPIO to control a lighting console over OSC, whilst also
|
|
|
|
controlling an LED strobe light with DMX data recieved over sACN.
|
|
|
|
|
|
|
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
2020-12-01 19:40:58 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include "sacn.h"
|
|
|
|
#include <ArduinoOSC.h>
|
|
|
|
#include "strobe_esp32.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2020-12-04 14:57:57 -05:00
|
|
|
This section to be configured by Lighting Control
|
|
|
|
*/
|
2020-12-01 19:40:58 -05:00
|
|
|
// -----------------------------------
|
|
|
|
// Configure the WiFi network
|
|
|
|
// -----------------------------------
|
|
|
|
const char ssid[] = "........";
|
|
|
|
const char pwd[] = "........";
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Configure the IPv4 network
|
|
|
|
// -----------------------------------
|
|
|
|
const IPAddress ip(127, 0, 0, 1);
|
|
|
|
const IPAddress subnet(255, 255, 255, 0);
|
|
|
|
const IPAddress gateway(127, 0, 0, 1);
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Configure OSC
|
|
|
|
// -----------------------------------
|
|
|
|
const String host = "127.0.0.1";
|
|
|
|
const uint16_t port = 7001;
|
2020-12-04 14:57:57 -05:00
|
|
|
const String pressed_addr = "/hog/playback/go/0";
|
|
|
|
const String pressed_value = "99.1";
|
|
|
|
const String released_addr = "/hog/playback/go/0";
|
2020-12-01 19:40:58 -05:00
|
|
|
const String released_value = "99.2";
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Configure E1.31 sACN
|
|
|
|
// -----------------------------------
|
2020-12-04 09:44:58 -05:00
|
|
|
const e131_listen_t sACN_mode = E131_UNICAST; // (uni|multi)cast
|
|
|
|
const uint16_t strobe_universe = 1;
|
|
|
|
const uint16_t strobe_address = 501;
|
|
|
|
|
2020-12-04 14:57:57 -05:00
|
|
|
/* DMX Value
|
|
|
|
| chan | Command | range | range |
|
|
|
|
|------+-----------+-------+------------|
|
|
|
|
| 1 | Intensity | 0- | 0-100% | 15 bit 2.4kHz PWM
|
|
|
|
| 2 | fine | 65535 | |
|
|
|
|
|------+-----------+-------+------------|
|
|
|
|
| 3 | Duration | 0-255 | 0.02-0.5s | 0.002s resolution
|
|
|
|
|------+-----------+-------+------------|
|
|
|
|
| 4 | Rate | 0-255 | 0.5-25hz | 0.1 hz resolution
|
|
|
|
|------+-----------+-------+------------|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
This section to be configured by the Fixtures Dept.
|
|
|
|
*/
|
2020-12-01 19:40:58 -05:00
|
|
|
const int button = A0; // A0, use 100nF to ground
|
|
|
|
const int led = LED_BUILTIN; // IO13
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2020-12-04 14:57:57 -05:00
|
|
|
Change nothing else unless you're really sure.
|
|
|
|
*/
|
2020-12-01 19:40:58 -05:00
|
|
|
|
2020-12-04 09:44:58 -05:00
|
|
|
//// device objects
|
|
|
|
Strobe *strobe = new Strobe(strobe_universe, strobe_address);
|
|
|
|
ESPAsyncE131 *e131 = new ESPAsyncE131();
|
|
|
|
|
2020-12-01 19:40:58 -05:00
|
|
|
//// Global button variables
|
|
|
|
bool pressed = false; // track button state
|
|
|
|
uint32_t change_time; // time of button press (ms)
|
|
|
|
|
|
|
|
/*
|
2020-12-04 14:57:57 -05:00
|
|
|
Arduino powerup
|
|
|
|
*/
|
2020-12-01 19:40:58 -05:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
2020-12-06 14:09:42 -05:00
|
|
|
Serial.println("Disabling Bluetooth.");
|
|
|
|
btStop();
|
|
|
|
|
2020-12-04 14:57:57 -05:00
|
|
|
//// start WiFi:
|
2020-12-01 19:40:58 -05:00
|
|
|
// set IPv4
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
WiFi.config(ip, gateway, subnet);
|
|
|
|
WiFi.begin(ssid, pwd);
|
|
|
|
|
|
|
|
// join 802.11
|
|
|
|
if (WiFi.config(ip, gateway, subnet)) {
|
|
|
|
Serial.print("Connected to ");
|
|
|
|
Serial.println(ssid);
|
|
|
|
Serial.print("IP address is ");
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
} else {
|
|
|
|
Serial.println("STA Failed to configure");
|
|
|
|
}
|
|
|
|
|
2020-12-04 09:44:58 -05:00
|
|
|
|
2020-12-04 14:37:47 -05:00
|
|
|
//// start sACN
|
|
|
|
if (!e131->subscribe(strobe_universe, sACN_mode)) {
|
2020-12-04 09:44:58 -05:00
|
|
|
Serial.println("Failed to start E1.31");
|
|
|
|
} else {
|
|
|
|
e131->onPacket(std::bind(&Strobe::recvData, strobe,
|
2020-12-04 14:37:47 -05:00
|
|
|
std::placeholders::_1));
|
2020-12-04 09:44:58 -05:00
|
|
|
Serial.println("Listening for sACN");
|
|
|
|
}
|
2020-12-04 14:57:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
//// start fixtures hardware:
|
2020-12-01 19:40:58 -05:00
|
|
|
// button
|
|
|
|
pinMode(button, INPUT_PULLUP);
|
2020-12-04 09:44:58 -05:00
|
|
|
if (!strobe->begin(led, 0)) {
|
2020-12-01 19:40:58 -05:00
|
|
|
Serial.println("Strobe failed to configure.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-04 14:57:57 -05:00
|
|
|
/*
|
|
|
|
Arduino process loop
|
|
|
|
*/
|
2020-12-01 19:40:58 -05:00
|
|
|
void loop() {
|
|
|
|
if (WiFi.status() != WL_CONNECTED) {
|
|
|
|
Serial.println("Waiting for WiFi...");
|
|
|
|
delay(1000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Be a remote trigger
|
|
|
|
//
|
|
|
|
bool val = !digitalRead(button);
|
|
|
|
if (val != pressed) {
|
|
|
|
pressed = val;
|
|
|
|
change_time = millis();
|
|
|
|
if (pressed) {
|
|
|
|
Serial.println("Pressed");
|
|
|
|
OscWiFi.send(host, port, pressed_addr, pressed_value);
|
|
|
|
} else {
|
|
|
|
Serial.println("Released");
|
|
|
|
OscWiFi.send(host, port, released_addr, released_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|