Skip to content

Instantly share code, notes, and snippets.

@maly
Last active December 21, 2016 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maly/5a5a5f30d76239b7829191166c8caed8 to your computer and use it in GitHub Desktop.
Save maly/5a5a5f30d76239b7829191166c8caed8 to your computer and use it in GitHub Desktop.
Arduino: Blinking LED Strip
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 50
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.
#define DATA_PIN 3
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
//fill whole stripe with one color
void wholecolor(CRGB col) {
for (int i=0;i<NUM_LEDS;i++) {
leds[i] = col;
}
FastLED.show();
}
//Turn it off
void off() {wholecolor(CRGB::Black);}
// Run 5 lights in segments by 10
void run5(CRGB col, int speed=200) {
for (int i=0;i<10;i++) {
leds[i] = col;
leds[i+10] = col;
leds[i+20] = col;
leds[i+30] = col;
leds[i+40] = col;
leds[i+9] = CRGB::Black;
leds[i+19] = CRGB::Black;
leds[i+29] = CRGB::Black;
leds[i+39] = CRGB::Black;
if (i>0) {
leds[i-1] = CRGB::Black;
} else {
leds[49] = CRGB::Black;
}
FastLED.show();
delay(speed);
}
}
uint8_t r=255,g=255,b=255;
void loop() {
//effect1
/*
for (int i=0;i<NUM_LEDS;i++) {
leds[i] = CRGB::Red;
if (i>0) {leds[i-1] = CRGB::Black;}
else {leds[NUM_LEDS-1] = CRGB::Black;}
FastLED.show();
delay(50);
}
*/
//Effect 2
/*
for (int i=0;i<NUM_LEDS;i++) {
leds[i] = col1;
if (i>0) {leds[i-1] = CRGB::Black;}
else {leds[NUM_LEDS-1] = CRGB::Black;}
leds[NUM_LEDS-i-1] = col2;
if (i<49) {leds[NUM_LEDS-i] = CRGB::Black;}
else {leds[0] = CRGB::Black;}
FastLED.show();
delay(20);
}
*/
wholecolor((CRGB)(b<<0 | g<<8 | r<<16));
delay(200);
r = r - 5;
if (r<10) r=255;
b = b - 7;
if (b<10) b=255;
g = g - 3;
if (g<10) g=255;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment