# Arduino rgb loop

So I have an rgb led and I can change the color with:

    setColor(r, g, b);


I want a loop to loop through all the possible combinations how can I do this?

• Other than with for loops? – Ignacio Vazquez-Abrams Oct 1 '16 at 14:42
• many ways to do this, for example here. Clearly this questions shows little to no research effort. – Xaser Oct 1 '16 at 14:45
• This is a pure Arduino software question, and so IMHO should be migrated to the Arduino stackexchange – gbulmer Oct 1 '16 at 14:45

This can be easily achieved with nested for loops:

int R;
int G;
int B;

void loop()
{
for (R = 0 ; R < 256 ; R++)
{
for (G = 0 ; G < 256 ; G++)
{
for (B = 0 ; B < 256 ; B++)
{
setColor(R,G,B);
}
}
};
}


It would be really nice if you put some more effort into your work... Hope it helps. Best of Luck!!

• The question shows no research effort (see help center), and so it might have helped the OP a bit more if you'd given some advice and direction rather than the entire answer (though your C, with its incorrect }; suggests that you are learning it, and not yet expert). The old saying is give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. Giving an answer robs the OP of the opportunity to learn! – gbulmer Oct 1 '16 at 15:51
• @gbulmer maybe i was caught up for finding something I finally know the answer to - yes im still learning :) . And i cant agree more on what you said , perhaps next time i'll try to teach rather than provide plain answers! Thx :) – Mero55 Oct 19 '16 at 19:08