Skip to content

Instantly share code, notes, and snippets.

@jclement
Created January 26, 2016 02:40
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 jclement/f4ba14aba2cb057c817a to your computer and use it in GitHub Desktop.
Save jclement/f4ba14aba2cb057c817a to your computer and use it in GitHub Desktop.
Arduino sketch for annoying xmas lights (ws2812b)
#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