diff --git a/src/main.cpp b/src/main.cpp index 79bd85e..ed52f64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,14 +49,20 @@ Adafruit_NeoKey_1x4 neokey; // Create the NeoKey object uint32_t Wheel(byte WheelPos); NeoKey1x4Callback blink(keyEvent evt); +int32_t multiplyColor(int32_t color,float v); + +#define BTN_IDX_0 3 +#define BTN_IDX_1 2 +#define BTN_IDX_2 1 +#define BTN_IDX_3 0 OneButton button1; void click1(); void doubleclick1(); void longPressStart1(); -Adafruit_MQTT_Publish button1Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button1"); -Adafruit_MQTT_Subscribe button1Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button1"); +Adafruit_MQTT_Publish button1Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button/1"); +Adafruit_MQTT_Subscribe button1Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button/1"); void button1ColorCB(uint32_t c); uint32_t releasecolor1; @@ -64,8 +70,8 @@ OneButton button2; void click2(); void doubleclick2(); void longPressStart2(); -Adafruit_MQTT_Publish button2Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button2"); -Adafruit_MQTT_Subscribe button2Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button2"); +Adafruit_MQTT_Publish button2Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button/2"); +Adafruit_MQTT_Subscribe button2Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button/2"); void button2ColorCB(uint32_t c); uint32_t releasecolor2; @@ -73,8 +79,8 @@ OneButton button3; void click3(); void doubleclick3(); void longPressStart3(); -Adafruit_MQTT_Publish button3Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button3"); -Adafruit_MQTT_Subscribe button3Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button3"); +Adafruit_MQTT_Publish button3Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button/3"); +Adafruit_MQTT_Subscribe button3Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button/3"); void button3ColorCB(uint32_t c); uint32_t releasecolor3; @@ -82,14 +88,14 @@ OneButton button4; void click4(); void doubleclick4(); void longPressStart4(); -Adafruit_MQTT_Publish button4Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button4"); -Adafruit_MQTT_Subscribe button4Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button4"); +Adafruit_MQTT_Publish button4Pub = Adafruit_MQTT_Publish(&mqtt, MQTT_BASETOPIC"/button/4"); +Adafruit_MQTT_Subscribe button4Color = Adafruit_MQTT_Subscribe(&mqtt, MQTT_BASETOPIC"/color/button/4"); void button4ColorCB(uint32_t c); uint32_t releasecolor4; -uint32_t presscolor = 0x555555; +//uint32_t presscolor = 0xa07020; @@ -207,24 +213,28 @@ void setup() { #endif + button1.setDebounceMs(10); button1.attachClick(click1); button1.attachDoubleClick(doubleclick1); button1.attachLongPressStart(longPressStart1); button1Color.setCallback(button1ColorCB); mqtt.subscribe(&button1Color); + button2.setDebounceMs(10); button2.attachClick(click2); button2.attachDoubleClick(doubleclick2); button2.attachLongPressStart(longPressStart2); button2Color.setCallback(button2ColorCB); mqtt.subscribe(&button2Color); + button4.setDebounceMs(10); button3.attachClick(click3); button3.attachDoubleClick(doubleclick3); button3.attachLongPressStart(longPressStart3); button3Color.setCallback(button3ColorCB); mqtt.subscribe(&button3Color); + button4.setDebounceMs(10); button4.attachClick(click4); button4.attachDoubleClick(doubleclick4); button4.attachLongPressStart(longPressStart4); @@ -249,40 +259,44 @@ void loop() { // Check each button, if pressed, light the matching neopixel - if (buttons & (1<<0)) { + if (buttons & (1<> 16; + byte g = color >> 8; + byte b = color; + + float maxV=255.0/max(r,max(g,b)); //limit so that no color component clips 255 + v=min(v,maxV); + + float rnew=constrain(r*v,0,255); + float gnew=constrain(g*v,0,255); + float bnew=constrain(b*v,0,255); + r=byte(rnew); + g=byte(gnew); + b=byte(bnew); + + int32_t c=(r<<16) + (g<<8) + b; + return c; +} + + // React to Ethernet events:- #ifndef WIFI void WiFiEvent(WiFiEvent_t event)