From d70e421db359b72f58e52aae5ff200a5ce1e04e6 Mon Sep 17 00:00:00 2001 From: Antoni K Date: Wed, 16 Sep 2020 12:39:45 +0800 Subject: [PATCH 1/2] Fix typo Added an "l" to Compatible PC RGB... --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index dd860131b..2d62bc12f 100644 --- a/readme.md +++ b/readme.md @@ -72,7 +72,7 @@ WS2811 | 12v | 3-LED segments WS2815 | 12v | GS8208 | 12v | -## 🧊 Compatibe PC RGB Fans and ARGB accessories +## 🧊 Compatible PC RGB Fans and ARGB accessories Brand | Model | Comments |---|---|---| Corsair | HD120 Fan | Uses WS2812B, data-in only From e7709d8463f22cbacbbca817d048f60a16bbcbfa Mon Sep 17 00:00:00 2001 From: NeariX67 <31779313+NeariX67@users.noreply.github.com> Date: Wed, 16 Sep 2020 21:21:26 +0200 Subject: [PATCH 2/2] Upload TouchBrightnessControl Usermod for ESP32 (#1183) * Upload Usermod * Fix missing : public Usermod * Increased default threshold, added touchPin #define Co-authored-by: Aircoookie --- .../ESP32_TouchBrightnessControl/readme.md | 19 ++++ .../usermod_touchbrightness.h | 89 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 usermods/ESP32_TouchBrightnessControl/readme.md create mode 100644 usermods/ESP32_TouchBrightnessControl/usermod_touchbrightness.h diff --git a/usermods/ESP32_TouchBrightnessControl/readme.md b/usermods/ESP32_TouchBrightnessControl/readme.md new file mode 100644 index 000000000..f210b3320 --- /dev/null +++ b/usermods/ESP32_TouchBrightnessControl/readme.md @@ -0,0 +1,19 @@ +# ESP32 Touch Brightness Control + +Toggle On/Off with a long press (800ms) +Switch through 5 brightness levels (defined in usermod_touchbrightness.h, values 0-255) with a short (100ms) touch + +## Installation + +Copy 'usermod_touchbrightness.h' to the wled00 directory. +in 'usermod_list.cpp' add this: + +> #include "usermod_touchbrightness.h" +above "void registerUsermods()" + +and + +> usermods.add(new TouchBrightnessControl()); +inside the "registerUsermods()" function + + diff --git a/usermods/ESP32_TouchBrightnessControl/usermod_touchbrightness.h b/usermods/ESP32_TouchBrightnessControl/usermod_touchbrightness.h new file mode 100644 index 000000000..1b7795925 --- /dev/null +++ b/usermods/ESP32_TouchBrightnessControl/usermod_touchbrightness.h @@ -0,0 +1,89 @@ +// +// usermod_touchbrightness.h +// github.com/aircoookie/WLED +// +// Created by Justin Kühner on 14.09.2020. +// Copyright © 2020 NeariX. All rights reserved. +// https://github.com/NeariX67/ +// Discord: @NeariX#4799 + + +#pragma once + +#include "wled.h" + +#define threshold 40 //Increase value if touches falsely accur. Decrease value if actual touches are not recognized +#define touchPin T0 //T0 = D4 / GPIO4 + +//Define the 5 brightness levels +//Long press to turn off / on +#define brightness1 51 +#define brightness2 102 +#define brightness3 153 +#define brightness4 204 +#define brightness5 255 + + +#ifdef ESP32 + + +class TouchBrightnessControl : public Usermod { + private: + unsigned long lastTime = 0; //Interval + unsigned long lastTouch = 0; //Timestamp of last Touch + unsigned long lastRelease = 0; //Timestamp of last Touch release + boolean released = true; //current Touch state (touched/released) + uint16_t touchReading = 0; //sensor reading, maybe use uint8_t??? + uint16_t touchDuration = 0; //duration of last touch + public: + + void setup() { + lastTouch = millis(); + lastRelease = millis(); + lastTime = millis(); + } + + void loop() { + if (millis() - lastTime >= 50) { //Check every 50ms if a touch occurs + lastTime = millis(); + touchReading = touchRead(touchPin); //Read touch sensor on pin T0 (GPIO4 / D4) + + if(touchReading < threshold && released) { //Touch started + released = false; + lastTouch = millis(); + } + else if(touchReading >= threshold && !released) { //Touch released + released = true; + lastRelease = millis(); + touchDuration = lastRelease - lastTouch; //Calculate duration + } + + //Serial.println(touchDuration); + + if(touchDuration >= 800 && released) { //Toggle power if button press is longer than 800ms + touchDuration = 0; //Reset touch duration to avoid multiple actions on same touch + toggleOnOff(); + colorUpdated(2); //Refresh values + } + else if(touchDuration >= 100 && released) { //Switch to next brightness if touch is between 100 and 800ms + touchDuration = 0; //Reset touch duration to avoid multiple actions on same touch + if(bri < brightness1) { + bri = brightness1; + } else if(bri >= brightness1 && bri < brightness2) { + bri = brightness2; + } else if(bri >= brightness2 && bri < brightness3) { + bri = brightness3; + } else if(bri >= brightness3 && bri < brightness4) { + bri = brightness4; + } else if(bri >= brightness4 && bri < brightness5) { + bri = brightness5; + } else if(bri >= brightness5) { + bri = brightness1; + } + colorUpdated(2); //Refresh values + } + + } + } +}; +#endif