Go Down

Topic: RGB led: can I put only 1 resistor at ground? (Read 14140 times) previous topic - next topic


I didn't notice any flickering. Note that even at 25-50hz the led is not flickering completely on/off, it's changing color at that frequency r->g->b->r... Etc. Brain is not so sensitive to hue flickering.

Unless of course the color is 255,0,0 or something similar.

Ok, I'm off to bed now, past midnight here. Later!


Nov 25, 2014, 03:01 am Last Edit: Nov 25, 2014, 03:14 am by oric_dan
Flickering doesn't mean completely on-off, it means perceiving a noticeable change in intensity. It may actually only be a few percent to be noticeable. This is why the AC mains use 50-60 Hz. Below that people perceive flickering, and it's very distracting.

This shows that a 1% voltage fluctuation is generally perceivable. It's not a hard threshold, much more complex than that.

Ok, tomorrow you can fix your code. Hint: what's the maximum duty cycle each of your Leds can have in the existing code? [I may be wrong, but think it's 33%]. Hint: the "fix" is duplicating line 2 of your ISR twice more.


Nov 25, 2014, 05:12 am Last Edit: Nov 25, 2014, 06:24 am by dlloyd
Had another idea for an RGB heartbeat indicator.

 Demultiplexing millis() for R,G,B using digitalWrite.
 The single resistor is returned through one PWM pin to set a stable intensity.
 As iteration speed slows, intensity remains constant eliminating flicker.
 Also, as iteration speed slows, perceived color varies, then jumping from color to color becomes apparent.
 Very low cpu cycles required, especially if direct port manipulation is used.
 No libraries or interrupts required.

Code: [Select]
int ledG = 8;   // LED Gnd
int pinR = 9;   // LED R
int pinG = 10;  // LED G
int pinB = 11;  // LED B

const byte intensity = 120; // 0 = off, 255 = full intensity

void setup() {
  pinMode(pinR, OUTPUT);
  pinMode(pinG, OUTPUT);
  pinMode(pinB, OUTPUT);
  analogWrite(ledG, (255 - intensity)); //PWM

void loop() {
  byte x = (millis() / 8) % 3; //125ms demultiplexer
  digitalWrite(pinR, 1 * ((x == 0) ? 1 : 0));
  digitalWrite(pinG, 1 * ((x == 1) ? 1 : 0));
  digitalWrite(pinB, 1 * ((x == 2) ? 1 : 0));

Go Up