-4
\$\begingroup\$

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?

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

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!!

\$\endgroup\$
  • 2
    \$\begingroup\$ 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! \$\endgroup\$ – gbulmer Oct 1 '16 at 15:51
  • \$\begingroup\$ @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 :) \$\endgroup\$ – Mero55 Oct 19 '16 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.