2 or 3 LED colors on a single digital pin

Hey friends.
The trick was successful. :partying_face:

Use two LEDs, two resistors and two additional capacitors...

Expand to show codes.
#define LED_OFF  0x00
#define LED_RED  0xD0
#define LED_BLUE 0x01
#define LED_BOTH 0xB2

const int LED_PIN = 3;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  TCCR2B ^= 5; // Freq Trick
}

void loop() {
  setLEDstate(LED_OFF);
  delay(1000);
  setLEDstate(LED_BOTH);
  delay(1000);
  setLEDstate(LED_BLUE);
  delay(1000);
  setLEDstate(LED_RED);
  delay(1000);
}

void setLEDstate(byte color) {
  analogWrite(LED_PIN, color);
}
1 Like