Arduino-HomeKit-ESP8266 icon indicating copy to clipboard operation
Arduino-HomeKit-ESP8266 copied to clipboard

PWMRANGE error

Open DziveQ opened this issue 3 years ago • 3 comments

Hi. I'm trying to use example simple_led and the only thing I changed was SSID name and password. When I'm uploading, I'm getting this error:

C:\Users\kacpe\AppData\Local\Temp\arduino_modified_sketch_215244\simple_led_accessory.c: In function 'led_update': simple_led_accessory.c:67:13: error: 'PWMRANGE' undeclared (first use in this function) 67 | int pwm = PWMRANGE - (int) (led_bri * 1.0 * PWMRANGE / 100.0 + 0.5f); | ^~~~~~~~ C:\Users\kacpe\AppData\Local\Temp\arduino_modified_sketch_215244\simple_led_accessory.c:67:13: note: each undeclared identifier is reported only once for each function it appears in exit status 1 'PWMRANGE' undeclared (first use in this function)

I'm using correct Port and Board settings (it's working with other sketches)

DziveQ avatar Feb 02 '22 18:02 DziveQ

Guys, I have the same problem. Googling for the PWMRANGE variable gave me the following issue:

1.) the change of PWMRANGE via analogWriteRange(new_range) is not possible! -> if you set 1000 or 255 for example there ist no change -> only 1023.

This issue has nothing to do with this project. However, I decided to try redefining the PWMRANGE variable. I just added a declaration int PWMRANGE = 1023; to the method led_update()

void led_update() {
	if (led_power) {
		int PWMRANGE = 1023;     // redefining PWMRANGE here
		int pwm = PWMRANGE - (int) (led_bri * 1.0 * PWMRANGE / 100.0 + 0.5f);
		analogWrite(PIN_LED, pwm);
		printf("ON  %3d (pwm: %4d of %d)\n", led_bri, pwm, PWMRANGE);
	} else {
		printf("OFF\n");
		digitalWrite(PIN_LED, HIGH);
	}
}

This is a very dirty solution. But it allowed me to compile the example.

kuznetsov-m avatar May 17 '22 22:05 kuznetsov-m

Con esta corrección me ha funcionado, el problema es que al poner el 100% de brillo se apaga, y al poner 0% se enciende del todo, alguien sabe algo? en definitiva funciona del revés

Lecturas monitor serie: (en este estado la barrita esta la luz al 100% de brillo, pero se apaga del todo) ON 100 (pwm: 0 of 1023)

(en este estado la barrita esta la luz al 0% de brillo, pero se enciende del todo) ON 0 (pwm: 1023 of 1023) OFF

dani34dag avatar Sep 09 '22 01:09 dani34dag

This is due to an old reference, for the esp8266 library that was since updated. #define PWMRANGE 1023 was removed https://github.com/esp8266/Arduino/pull/7456/

In the default library this was set to the upstream value of 255: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/core_esp8266_wiring_pwm.cpp#L29

FrenchBen avatar Sep 13 '22 00:09 FrenchBen