LED RGB

LED RGB

This page is to Setup and Config LED RGB

Hardware and Software

Hardware

LED RGB

Software

Arduino IDE

Sanki Notes

    • R + G B ( 0 V 1 2 )

Examples

This example is ..........

            1. #include <DigisparkRGB.h>

            2. /*

            3. Digispark RGB

            4. This example shows how to use soft PWM to fade 3 colors.

            5. Note: This is only necessary for PB2 (pin 2) - Blue, as Red (pin 0) and Green (pin 1) as well as pin 4 support the standard Arduino analogWrite() function.

            6. This example code is in the public domain.

            7. */

            8. byte RED = 0;

            9. byte BLUE = 2;

            10. byte GREEN = 1;

            11. byte COLORS[] = {RED, BLUE, GREEN};

            12. // the setup routine runs once when you press reset:

            13. void setup() {

            14. DigisparkRGBBegin();

            15. }

            16. void loop ()

            17. {

            18. //direction: up = true, down = false

            19. boolean dir = true;

            20. int i = 0;

            21. while(1)

            22. {

            23. fade(COLORS[i%3], dir);

            24. i++;

            25. dir = !dir;

            26. }

            27. }

            28. void fade(byte Led, boolean dir)

            29. {

            30. int i;

            31. //if fading up

            32. if (dir)

            33. {

            34. for (i = 0; i < 256; i++)

            35. {

            36. DigisparkRGB(Led, i);

            37. DigisparkRGBDelay(25);//1);

            38. }

            39. }

            40. else

            41. {

            42. for (i = 255; i >= 0; i--)

            43. {

            44. DigisparkRGB(Led, i);

            45. DigisparkRGBDelay(25);//1);

            46. }

            47. }

            48. }