File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 2020#define LED_PIN 5
2121
2222int brightness = 0 ; // how bright the LED is
23- int fadeAmount = 5 ; // how many points to fade the LED by
23+ int fadeAmount = 4 ; // how many points to fade the LED by
2424
2525// Arduino like analogWrite
2626// value has to be between 0 and valueMax
27- void ledcAnalogWrite (uint8_t pin, uint32_t value, uint32_t valueMax = 255 ) {
27+ void ledcAnalogWrite (uint8_t pin, uint32_t value, uint32_t valueMax = 256 ) {
2828 // calculate duty, 4095 from 2 ^ 12 - 1
29- uint32_t duty = (4095 / valueMax) * min (value, valueMax);
29+ uint32_t duty = (4096 / valueMax) * min (value, valueMax);
3030
3131 // write duty to LEDC
3232 ledcWrite (pin, duty);
@@ -45,7 +45,7 @@ void loop() {
4545 brightness = brightness + fadeAmount;
4646
4747 // reverse the direction of the fading at the ends of the fade:
48- if (brightness <= 0 || brightness >= 255 ) {
48+ if (brightness <= 0 || brightness >= 256 ) {
4949 fadeAmount = -fadeAmount;
5050 }
5151 // wait for 30 milliseconds to see the dimming effect
You can’t perform that action at this time.
0 commit comments