Hi, I tried to adjust the brightness of the white-led strip with the slider from the Blynk app and esp32. But when I move the slider just a little bit, the led strip lights up to the maximum brightness, so it’s just like the on/off button.
actually esp32 doesn’t support analogwrite that’s why I used digitalwrite, but after reading your reply I searched the internet and found the analogwrite library for esp32, and it solved my problem.
Thanks for the advice.
That would be the solution with an ESP8266, but the ESP32 doesn’t support analogWrite. Instead you have to use ledcSetup(ledChannel, freq, resolution) and ledcAttachPin(GPIO, channel) then ledcWrite(channel, dutycycle) to do the dimming.
Of course, you’ll kill your ESP32 almost immediately if you attach any substantial length of 5v LED strip directly to your ESP32, and it will never run at full brightness anyway - because it needs 5v rather than the 3.3v that the ESP32 outputs.
You need to use a suitable MOSFET to achieve the correct result and to protect your ESP32.
It’s only really useful if you’re trying to re-use code written for the ESP8266 or Arduino boards and you don’t want to make too many changes to your sketch.
Otherwise the ESP32 commands are straightforward to use.
I recently updated the code on one of my ESP8266 based RGB dimmers and suddenly they went to full brightness at 255 rather than 1023. After lots of head-scratching, I realised that recent versions of the ESP core (V3.0.0 onwards I think) changed the way that digitalWrite works - to make it backwards compatible with Arduino hardware.
This can be overridden, or even changed to 0-65k, but you can waste a lot of time if you don’t know about the change.
// NOTE:
// Sketch tested OK with pubsubclient=2.8.0 and esp8266=2.7.1 (with esp8266=2.5 tz setting will not compile)
// Sketch CRASHES with pubsublient=2.8.0 and esp8266=3.0.2
The code this happens for uses PUBLISH (and no SUBSCRIBE) but also provides a WEB SERVER for browser access.
The tz comment is about timezones which was fixed in other arduino libs after 2.5.