Skip to content

Instantly share code, notes, and snippets.

Last active Jul 13, 2018
What would you like to do?
Mirror the onboard RGB LED on Particle devices to an external RGB LED
// Automatically mirror the onboard RGB LED (Photon, Electron) to an external RGB LED
// LEDMirror.cpp
// Class set-up
class LEDMirror {
LEDMirror(pin_t r, pin_t g, pin_t b) : pin_r(r), pin_g(g), pin_b(b) {
pinMode(pin_r, OUTPUT);
pinMode(pin_g, OUTPUT);
pinMode(pin_b, OUTPUT);
RGB.onChange(&LEDMirror::handler, this);
void handler(uint8_t r, uint8_t g, uint8_t b) {
analogWrite(pin_r, 255 - r);
analogWrite(pin_g, 255 - g);
analogWrite(pin_b, 255 - b);
pin_t pin_r;
pin_t pin_g;
pin_t pin_b;
// myProject.ino
// Example Usage: Connect an external RGB LED to D0, D1 and D2 (R, G, and B) and place this in your user firmware
LEDMirror myLED(D0, D1, D2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment