Created
January 26, 2016 02:40
-
-
Save jclement/f4ba14aba2cb057c817a to your computer and use it in GitHub Desktop.
Arduino sketch for annoying xmas lights (ws2812b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Arduino.h" | |
#include <Adafruit_NeoPixel.h> | |
#define PIN 4 | |
#define LED_COUNT 60 | |
// Create an instance of the Adafruit_NeoPixel class called "leds". | |
// That'll be what we refer to from here on... | |
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800); | |
void setup() | |
{ | |
leds.begin(); // Call this to start up the LED strip. | |
} | |
void lightColor(int pos) { | |
if (pos % 6 == 0) { | |
leds.setPixelColor(pos, 10, 0, 0); | |
} else if (pos % 6 == 1) { | |
leds.setPixelColor(pos, 0, 10, 0); | |
} else if (pos % 6 == 2) { | |
leds.setPixelColor(pos, 0, 0, 10); | |
} else if (pos % 6 == 3) { | |
leds.setPixelColor(pos, 0, 10, 10); | |
} else if (pos % 6 == 4) { | |
leds.setPixelColor(pos, 10, 10, 0); | |
} else { | |
leds.setPixelColor(pos, 10, 0, 10); | |
} | |
} | |
int l = 0; | |
int d = 1; | |
void loop() | |
{ | |
// Ride the Rainbow Road | |
for (int i=0; i<=LED_COUNT-1; i++) { | |
leds.setPixelColor(i, 0, 0, 0); | |
} | |
for (int i=0; i<=LED_COUNT-1; i++) { | |
if ((l+ i)%3== 0) | |
lightColor(i); | |
} | |
leds.show(); | |
l += d; | |
if (l == 0 || l >= LED_COUNT) { | |
d *=-1; | |
} | |
delay(40); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment