I’ve encountered strange behaviour where there’s siginificant 1-2 second delay between running analogwrite and having that new value actually be outputted from the pin.
I reduced the problem on very simple test that works as it should on XIAO SAMD21 but when uploaded to ESP32-C3 it causes 1-2 seconds delay between the input pin getting high and the output reflecting the change. If I change the analogWrite to digitalWrite the delay is gone and output reflects the input instantaneously on ESP32-C3 also.
What do you expect from analogWrite() on the XIAO ESP32C3?
It cannot provide analog voltage output because it does not have a built-in DAC.
For PWM output, please see the following instead of analogWrite().
//\Arduino15\packages\esp32\hardware\esp32\2.0.6\cores\esp32\esp32-hal-ledc.c and .h
edit:
I have confirmed that the following code works, needed delay() in the loop. I do not know why.