Skip to content

Instantly share code, notes, and snippets.

@fraguada
Last active December 11, 2015 04:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fraguada/4547404 to your computer and use it in GitHub Desktop.
Save fraguada/4547404 to your computer and use it in GitHub Desktop.
A quick attempt at fading from solid color to none...
//adapted from LEDneltKit written bu Adafruit and found here:
//https://github.com/adafruit/LPD8806/tree/master/examples/LEDbeltKit
//Fades a color in and out
//2013.06.04 - Luis E. Fraguada
//looking for suggestions!
#include "LPD8806.h"
#include "SPI.h"
int dataPin = 16;
int clockPin = 15;
LPD8806 strip = LPD8806(12, dataPin, clockPin);
void setup()
{
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
for(int i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);
strip.show();
}
void loop()
{
pulse(127,127,127,100, 10); //r from 0 to 127, g from 0 to 127, b from 0 to 127, steps, wait
}
//pulse
void pulse(uint8_t r, uint8_t g, uint8_t b, uint8_t steps, uint8_t wait)
{
int t = 0;
float lev = 0;
boolean dir = true;
byte r2, g2, b2;
while(1){
if(t < steps && dir)
{
t++;
lev = ((float)t / (float)steps);
}
else
{
dir = false;
if(t > 0){
t--;
lev = ((float)t / (float)steps);
}
else {
dir = true;
}
}
for(int i=0; i<strip.numPixels(); i++) {
r2 = (byte)((float)r * lev);
g2 = (byte)((float)g * lev);
b2 = (byte)((float)b * lev);
strip.setPixelColor(i, r2, g2, b2);
}
strip.show();
delay(wait);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment