Skip to content

Instantly share code, notes, and snippets.

@caitlinsdad
Last active April 5, 2019 22: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 caitlinsdad/6d1858feeaf9fb4e71c89b3cf23b4342 to your computer and use it in GitHub Desktop.
Save caitlinsdad/6d1858feeaf9fb4e71c89b3cf23b4342 to your computer and use it in GitHub Desktop.
Game of Thrones Light Up Map
//#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_NeoPixel.h>
#define bright 25
#define PIN 6
#define PIN2 10
#define PIN3 9
#define PIN4 12
#define NUM_LEDS 29
#define NUM_LEDS2 29
#define NUM_LEDS3 29
#define NUM_LEDS4 29
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS2, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(NUM_LEDS3, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(NUM_LEDS4, PIN4, NEO_GRB + NEO_KHZ800);
void setup() {
randomSeed(analogRead(0));
strip.begin();
strip.setBrightness(bright);
strip.show(); // Initialize all pixels to 'off'
strip2.begin();
strip2.setBrightness(bright);
strip2.show(); // Initialize all pixels to 'off'
strip3.begin();
strip3.setBrightness(bright);
strip3.show(); // Initialize all pixels to 'off'
strip4.begin();
strip4.setBrightness(bright);
strip4.show(); // Initialize all pixels to 'off'
// CircuitPlayground.begin();
// CircuitPlayground.setBrightness(20);
// CircuitPlayground.clearPixels();
}
void loop() {
for(int i = 0; i < 200; i++ ) {
Fire(55,120,40,i);
}
setAllslow(255, 0, 0);
sparklered();
setAll(0, 0, 0);
delay(2000);
setAllslow(0, 0, 255);
sparkleblue();
setAll(0, 0, 0);
delay(2000);
}
// from work done by Mark Kriegsman (called “Fire2012”).
void Fire(int Cooling, int Sparking, int SpeedDelay, int loopcount) {
static byte heat[NUM_LEDS];
int cooldown;
// Step 1. Cool down every cell a little
for( int i = 0; i < NUM_LEDS; i++) {
cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
if(cooldown>heat[i]) {
heat[i]=0;
} else {
heat[i]=heat[i]-cooldown;
}
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
}
// Step 3. Randomly ignite new 'sparks' near the bottom
if( random(255) < Sparking ) {
int y = random(7);
heat[y] = heat[y] + random(160,255);
//heat[y] = random(160,255);
}
// Step 4. Convert heat to LED colors
for( int j = 0; j < NUM_LEDS; j++) {
setPixelHeatColor(j, heat[j] );
}
showStrip(loopcount);
delay(SpeedDelay);
}
void setPixelHeatColor (int Pixel, byte temperature) {
// Scale 'heat' down from 0-255 to 0-191
byte t192 = round((temperature/255.0)*191);
// calculate ramp up from
byte heatramp = t192 & 0x3F; // 0..63
heatramp <<= 2; // scale up to 0..252
// figure out which third of the spectrum we're in:
if( t192 > 0x80) { // hottest
setPixel(Pixel, 255, 255, heatramp);
} else if( t192 > 0x40 ) { // middle
setPixel(Pixel, 255, heatramp, 0);
} else { // coolest
setPixel(Pixel, heatramp, 0, 0);
}
}
void showStrip(int loopcounter) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
if (loopcounter > 100)strip.show();
strip2.show();
strip3.show();
strip4.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
strip2.setPixelColor(Pixel, strip.Color(red, green, blue));
strip3.setPixelColor(Pixel, strip.Color(red, green, blue));
strip4.setPixelColor(Pixel, strip.Color(red, green, blue));
// CircuitPlayground.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip(201);
}
void setAllslow(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
showStrip(201);
delay(50);
}
}
void sparklered() {
for(int i = 0; i < 80; i++ ) {
int randompixel = random(28);
setPixel(randompixel, 255, 255, 255);
showStrip(201);
delay(20);
setPixel(randompixel, 255, 0, 0);
showStrip(201);
delay(20);
}
}
void sparkleblue() {
for(int i = 0; i < 80; i++ ) {
int randompixel = random(28);
setPixel(randompixel, 255, 255, 255);
showStrip(201);
delay(20);
setPixel(randompixel, 0, 0, 255);
showStrip(201);
delay(20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment