[solved] Emulating RGB led on touchscreen

I currently have a project based on the P1 placed in an enclosure where the only interface to the outside world is a capacitive touchscreen. I’d like to emulate the current state of the RGB diode on the screen itself but in order to do so need to be able to “read in” the current state of the 3 led outputs, much like the buttonMirror() functionality but in firmware rather than hardware. pulseIn() may be an option but I’m unsure if it will work with the pins being outputs, I will test this at the next opportunity. If this does work, what is the pwm frequency, 500 Hz? I know the RGB timing runs off hardware interrupts using Timer2. Are there accessible system-level registers that hold the last set value/dutycycle of the pwm outputs?

Have you looked at RGB.onChange()?

1 Like

My understanding of RGB.onChange() is that it will only trigger when the mode changes (and hence the RGB led color does); does it trigger whenever the dutycycle changes but the color remains the same, e.g. during breathing?

Nope this triggers when the colour changes in any way.

Not too much to interpret wrong on that IMO

When they say “color” they mean the entire RGB 24bit number, so when any of the RGB components changes the handler is called.

But this also means that the handler should be kept as short and leave as fast as possible. Best only setting a volatile global variable that will be used in loop() to mirror the colour.

1 Like

Tremendous! Keeping the handler light weight is not an issue at all, I’ll simply be copying over the rgb value.

2 Likes