None of the code presented shows the setup of the LEDC API; timer configuration and channel configuration. Would you agree that if there is an issue with the timer configuration then the configuration error would be garbage in to the applying of a PWM value?
I can not confirm your findings that the pwm output does not go to 0. Here is a test sketch which uses an interrupt on pin 21 to read the pwm pulse count output of pin 23.
Jumper pin 21 to pin 23 for this test.
I would verify that your mapping works at you intend. Perhaps use constrain.
const int output = 23;
const int input = 21;
volatile uint32_t count;
uint32_t copyCount;
uint32_t lastRead;
uint32_t switchCount;
// setting PWM properties
String sliderValue = "0";
const int freq = 100;
const int ledChannel = 0;
const int resolution = 8;
//interrupt counter
void IRAM_ATTR isr() {
count++;
}
void setup() {
// Serial port for debugging purposes
Serial.begin(115200);
pinMode(input, INPUT_PULLDOWN);
attachInterrupt(input, isr, RISING);
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(output, ledChannel);
ledcWrite(ledChannel, sliderValue.toInt());
}
void loop() {
ledcWrite(ledChannel, sliderValue.toInt());
if (millis() - lastRead >= 1000) //read interrupt count every second
{
lastRead += 1000;
// disable interrupts,make copy of count,reenable interrupts
noInterrupts();
copyCount = count;
count = 0;
interrupts();
Serial.println(copyCount);
switchCount++;
}
if (switchCount == 5)
sliderValue = "1";
if (switchCount == 10)
{
sliderValue = "0";
switchCount = 0;
}
}
Me neither. It goes down to 0 fine for me.
Any chance of the cause of this behavior being on the client side? Perhaps the slider code doesn't allow the used variable to go down to 0?