Hi i am trying to toggle the inbuilt RGB LED of the ESP32-C6 (with as goal for it to be the status of the device: connecting, connected, error...). I did this with a timer with a callback but this does not work. My LED is continiously red, but should be toggling green/red. When i use this code in the loop function it works without any problems.
What makes it that rgbLedWrite cannot be used in a interupt?
Do you know which of the following is the reason for it not working when the code is in onTimer()?
a) onTimer() is not being called
b) onTimer() is being called, but rgbLedWrite() doesn't work
c) onTimer() is being called, but Serial.println() stops it from working
d) something else I haven't thought of
If you don't know, you could find out by moving parts of the code from onTimer() into loop(). E.g. first move everything except ledState = !ledState; into loop().
I don't think it's being used in an interrupt based on this information.
I do think that the problem lies wiht the rgbLedWrite() function. When removing the serial.println(which i added to see if the boolean was being updated) and only keeping the state change in the onTimer function the led blinks Red/Green as expected.
Is that a solution for you?
I don't know why rgbLedWrite() wouldn't work from onTimer().
Perhaps you could find out by looking at the code for rgbLedWrite. I'm not familiar with that function, because all my ESP32 boards don't have a built in RGB LED.
You do you but that attitude will not be a good one in this hobby.
What you want to do is possible, trust me. Why it isn't working is a mystery. Problems like this are an opportunity to learn through experiments and research.
I wanted you to take less than seven minutes on an experiment that might have advanced our collective knowledge around your issue.
What will you do with real problems that you can't just decide to take an easy way out by changing your mind about what you want to accomplish?
Every flaw is a challenge. I see ppl entirely satisfied with dodgy projects. I think things like this should be run to ground. There is an objective reality here, things can be traced to reasons.