Skip to content

Instantly share code, notes, and snippets.

@akirayou
Created February 10, 2019 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akirayou/6783a2404fa39664ec77fe49bcd1a18d to your computer and use it in GitHub Desktop.
Save akirayou/6783a2404fa39664ec77fe49bcd1a18d to your computer and use it in GitHub Desktop.
#include <WiFi.h>
#include <WebServer.h> // https://github.com/zhouhan0126/WebServer-esp32
#include <DNSServer.h>
#include <WiFiManager.h> // https://github.com/zhouhan0126/WIFIMANAGER-ESP3
#include <FastLED.h> //https://github.com/FastLED/FastLED
#include <WiFiUdp.h>
#include <ArduinoOSC.h> //https://github.com/hideakitai/ArduinoOSC
//#define DEBUG_UDP
void serialSetup(){
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\n Starting");
}
void wifiSetup(){
// is configuration portal requested?
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
if(false){//select SSID
//wifiManager.setTimeout(120);
if (!wifiManager.startConfigPortal("OndemandAP")) { //Enforce configration at boot time
Serial.println("Time out to set WiFi configuration");
}
}else{//automatic connection
wifiManager.autoConnect("AutoConnectAP"); //Normal auto connection
}
//if you get here you have connected to the WiFi
IPAddress ipadr = WiFi.localIP();
Serial.println("connected(^^)");
Serial.println("local ip");
Serial.println(ipadr);
Serial.println(WiFi.SSID());
}
const uint16_t max_pixels = 170; //NeoPiexel の LED素子数
const uint8_t neopixel_gpio = 13; //Nexpixel LED PIN
const uint16_t max_dmx_ch = max_pixels * 3;
uint8_t dmx[max_pixels*3] = {}; //DMX 1univers : 512ch
CRGB leds[max_pixels];
OscWiFi osc;
String mixerIP="255.255.255.255";
void ledSetup(){
FastLED.addLeds<WS2812B, neopixel_gpio, GRB>(leds, max_pixels);
FastLED.setBrightness(10); //max255
osc.begin(9000);
osc.subscribe("/0/dmx/*", [](OscMessage& m)
{
const char *chStr=m.address().c_str();
while(*chStr)chStr++;
while(*chStr!='/')chStr--;
chStr++;
unsigned char ch=atoi(chStr);
float v=m.arg<float>(0);
if(1.0<v)v=1.0;
if(v<0)v=0;
if(ch<3*max_pixels) dmx[ch]=v*255;
mixerIP=m.ip();
Serial.print((int)ch); Serial.print(" ");
Serial.print(v); Serial.println();
});
}
static WiFiUDP debugUdp;
float touchBase=0;
void setup() {
serialSetup();
wifiSetup();
debugUdp.begin(12345);
ledSetup();
touchBase=touch();
}
int touch(){
return touchRead(T8);
}
/* Touch ID list
T0 GPIO4
T1 GPIO0
T2 GPIO2
T3 GPIO15
T4 GPIO13
T5 GPIO12
T6 GPIO14
T7 GPIO27
T8 GPIO33
T9 GPIO32
*/
void loop() {
/*
//Just for check my circuits
Serial.print(touchRead(T0));
Serial.print(" ");
Serial.print(touchRead(T1));
Serial.print(" ");
Serial.print(touchRead(T2));
Serial.print(" ");
Serial.print(touchRead(T3));
Serial.print(" ");
Serial.print(touchRead(T4));
Serial.print(" ");
Serial.print(touchRead(T5));
Serial.print(" ");
Serial.print(touchRead(T6));
Serial.print(" ");
Serial.print(touchRead(T7));
Serial.print(" ");
Serial.print(touchRead(T8));
Serial.print(" ");
Serial.print(touchRead(T9));
Serial.println("");
*/
osc.parse();
int a=touch();
#ifdef DEBUG_UDP
debugUdp.beginPacket("255.255.255.255",12345);
debugUdp.print(a);
debugUdp.print(" ");
debugUdp.print(touchBase);
debugUdp.endPacket();
#endif
static int count=0;
static bool nowState=false;
bool nextState=touchBase - a> 5;
if(nextState){
touchBase=0.0001f*a+0.9999f*touchBase;
}else{
touchBase=0.01f*a+0.99f*touchBase;
}
if(nowState!=nextState){
count++;
if(count>5){
count=0;
nowState=nextState;
osc.send(mixerIP,7700,"/1/push1",nowState?255:0);
Serial.print("send to");
Serial.println(mixerIP);
}
}else{
count=0;
}
for(int i = 0; i < max_pixels; i++){
leds[i] = CRGB(dmx[i*3], dmx[i*3 + 1], dmx[i*3 + 2]);
}
FastLED.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment