ATTiny85 RGB Led color changing LED
 DuinoKit Tiny (Under Development)   Started by Daniel Alich   2018-01-28 21:36:21 -05:00   Comments: 2    Viewed: 268

  1. Daniel Alich
    Daniel Alich Member Staff Member
    This is a simple example for DigiSpark for controling the RGB LED
    #include <DigisparkRGB.h>  // <DigisparkRGB.h> libary file can be found here...  https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkRGB

    /*
    Digispark RGB
    This example shows how to use soft PWM to fade 3 colors.
    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.
    This example code is in the public domain.

    */

    byte RED = 0;
    byte BLUE = 2;
    byte GREEN = 1;
    byte COLORS[] = {RED, BLUE, GREEN};

    // the setup routine runs once when you press reset:
    void setup() {
    DigisparkRGBBegin();
    }

    void loop ()
    {
    //direction: up = true, down = false
    boolean dir = true;
    int i = 0;
    while(1)
    {
    fade(COLORS[i%3], dir);
    i++;
    dir = !dir;
    }
    }

    void fade(byte Led, boolean dir)
    {
    int i;
    //if fading up
    if (dir)
    {
    for (i = 0; i < 256; i++)
    {
    DigisparkRGB(Led, i);
    DigisparkRGBDelay(25);//1);
    }
    }
    else
    {
    for (i = 255; i >= 0; i--)
    {
    DigisparkRGB(Led, i);
    DigisparkRGBDelay(25);//1);
    }
    }
    }
    Daniel Alich, 2018-01-28 21:36:21 -05:00
  2. Ron Johnson
    Ron Johnson Member Murphy, NC
    Now that I have a little more time, I want to try this PWM example and maybe some others from Arduino.cc. Thanks Daniel! I need to understand how this works :)
    Ron Johnson, 2018-02-15 12:44:14 -05:00
  3. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!