1

I have 2 sets of RGB Leds, each set is driven by 3 OUTPUT analog pins of the arduino, as illustrated below: enter image description here

The code is supposed to put on HIGH the 6 analog pins at the same time so that the Leds light up all at the same time, but when I run it, there's a latency between the 2 groups of Leds. Here's the code:

const int r[2] = {3, 9};
const int g[2] = {5, 10};
const int b[2] = {6, 11};

const int red[3] = {255, 0, 0}; const int green[3] = {0, 255, 0}; const int blue[3] = {0, 0, 255};

int* colors[3] = {red, blue, green};

void setup() { for(int i=0; i<2; i++){ pinMode(r[i], OUTPUT); pinMode(g[i], OUTPUT); pinMode(b[i], OUTPUT); } }

void setColor(int r, int g, int b, int color[]){ int R = 255 - color[0]; int G = 255 - color[1]; int B = 255 - color[2]; analogWrite(r, R); analogWrite(g, G); analogWrite(b, B); }

void loop() { for(int c=0; c<3; c++){ setColor(r[0], g[0], b[0], colors[c]); setColor(r[1], g[1], b[1], colors[3-c-1]); delay(1000); } }

I should point out that the values of the resistors are in my circuit are different than in the diagram.

Is there something wrong in the wiring or in the code that prevents the Leds from wiring all at the same time?

EDIT: I tried the code one more time on the arduino and all Leds lit up at the same time. That happened in the past, but sometimes there's just a latency that I can neither explain nor fix...

S.E.K.
  • 53
  • 4

0 Answers0