Skip to content

Commit 69baa14

Browse files
authored
feat(ledc): Adjust LED fade parameters for new maximum values
1 parent 11dcd5c commit 69baa14

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

libraries/ESP32/examples/AnalogOut/LEDCSoftwareFade/LEDCSoftwareFade.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#define LED_PIN 5
2121

2222
int 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

0 commit comments

Comments
 (0)