RGB troubles, mirrorTo() to the rescue

Say you have a friend who designs an amazing PCB based on the P2 or other Particle device using an external RGB status LED. Then say that the footprint used in Altium, KiCad or previously known as) EagleCad has the wrong pin assignments or your friend is not paying attention to the connections from default Particle RGB pins to the RGB LED colors and gets the assignment wrong. Or say your friend used MOSFETs to drive LEDs (to get more current) and now the signals are inverted (HIGH turn OFF an LED). Or they may have the colors right but connected the RGB LEDs as commond anode instead of the default common cathode... just saying. Now they go and get the board fabricated in full confidence of their design.

There is a way you can help your friend to avoid having to redesign and refabricate the board by using the magic of mirrorTo() providing a sofware-only solution!

The mirrorTo() DeviceOS function is normally used for mapping an external RGB LED to a set of pins assigned by you. The function takes several arguments:

RGB.mirrorTo(pinr, ping, pinb, invert, bootloader);

pinr: PWM-enabled pin number connected to red LED
ping: PWM-enabled pin number connected to green LED
pinb: PWM-enabled pin number connected to blue LED
invert (optional): true if the connected RGB LED is common-anode, false if common-cathode (default).
bootloader (optional): if true, the RGB mirroring settings are saved in DCT and are used by the bootloader.If false, any previously stored configuration is removed from the DCT and RGB mirroring only works while the firmware is running (default). Do not use the true option for bootloader from STARTUP().

What's interesting, and as confirmed by @Rickas7, is that you can mirror the default RGB colors pins to themselves! Internally, the red, green and blue LED pins are:

	LED_PIN_RED
	LED_PIN_GREEN
	LED_PIN_BLUE

So, for example, say you have the following close, but not close enough RGB circuit. The colors are mixed up and RGB is now BRG! Fortunately, a HIGH on a LED pin still turns ON the corresponding LED (not inverted).

The RED output goes the BLUE LED, the GREEN output to the RED LED and the BLUE output goes to the GREEN LED. This can easily fixed by remapping the RGB pin colors with:

RGB.mirrorTo(LED_PIN_BLUE, LED_PIN_RED, LED_PIN_GREEN, false);

If you have an RGB LED, with the colors correctly wired but connected as common ANODE, you can fix that using:

RGB.mirrorTo(LED_PIN_RED, LED_PIN_GREEN, LED_PIN_BLUE, true);

You and your friend can now breath a sigh of relief :wink:

5 Likes

I'd say you are a GOOD friend.
Thanks for the tip, PK.

3 Likes