Skip to content

Instantly share code, notes, and snippets.

@dmiddlecamp
Last active August 29, 2015 14:11
Show Gist options
  • Save dmiddlecamp/85ed457a53f86258983b to your computer and use it in GitHub Desktop.
Save dmiddlecamp/85ed457a53f86258983b to your computer and use it in GitHub Desktop.
Holiday Strip code
// This #include statement was automatically added by the Spark IDE.
#include "neopixel/neopixel.h"
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 300
#define PIXEL_TYPE WS2812B
int reds[PIXEL_COUNT];
int greens[PIXEL_COUNT];
int blues[PIXEL_COUNT];
//setup the strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int idx = 0, a = 0;
int cheer = 0;
double brightness = 1;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Serial.begin(9600);
Spark.subscribe("cheer", onCheer);
}
void onCheer(const char *topic, const char *data) {
Serial.println("detected cheer");
cheer += 5;
}
void loop(){
if (idx >= PIXEL_COUNT) {
idx = 0;
}
if (a >= PIXEL_COUNT) {
a = 0;
}
int energy = (cheer <= 0) ? random(32) : 191 + random(64);
bool state = random(2) == 1;
reds[idx] = (state) ? energy : 0;
greens[idx] = (!state) ? energy : 0;
blues[idx] = (cheer > 0) ? random(255) : 0;
int numPixels = strip.numPixels();
for(int i=0;i<numPixels;i++) {
uint32_t color = strip.Color(reds[i], greens[i], blues[i]);
if (cheer > 0) {
color = strip.Color(random(255), random(255), random(255));
}
strip.setPixelColor((i+a)%numPixels, color);
//b.ledOn((i+a)%12, reds[i] * brightness, greens[i] * brightness, blues[i] * brightness);
}
strip.show();
a++;
idx++;
//state = !state;
if (cheer > 0) {
cheer--;
}
// bool anyButton = b.buttonOn(1) || b.buttonOn(2) || b.buttonOn(3) || b.buttonOn(4);
// if (anyButton) {
// Spark.publish("cheer", "5");
// delay(100);
// }
//Wait a mo'
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment