bruhautomation / ESP-MQTT-JSON-Multisensor

(OBSOLETE) ESP MQTT JSON Multisensor for Home Assistant. Supported sensors include the TEMT6000 light, AM312 PIR, DHT22 temperature/humidity sensors. RGB led supports flash, fade, and transition. Over-The-Air (OTA) uploading, too!
https://youtu.be/jpjfVc-9IrQ
Apache License 2.0
340 stars 152 forks source link

LED brightness #34

Open JonasArnold opened 6 years ago

JonasArnold commented 6 years ago

The maximum analogWrite on the ESP8266 value is not 255 (as in the code) but 1023. Because of that the LED is much less bright than it could theoretically be. Adapting the map-command results in the following problems:

I tried adapting the code but I failed at the transition-part. The following piece of code (in the callback-function) should work fine:

realBrightness = map(brightness, 0, 255, 0, 1023);
realRed = int(map(red, 0, 255, 0, realBrightness));
realGreen = int(map(green, 0, 255, 0, realBrightness));
realBlue = int(map(blue, 0, 255, 0, realBrightness));

realBrightness, realRed, realGreen, realBlue must now be integer-variables.

Now theoretically only the problem with the fade time is left: I tried increasing the number of steps from 1020 to 4090 or so... but then I failed making the whole process faster (more steps @ same time -> the Count-Loop must be processed more oftenly -> the whole loop must be faster)...

By the way you also need to adapt the following if-condition: // Defensive driving: make sure val stays in the range 0-255 if (val > 1023) { val = 1023; }