Last active
November 3, 2016 18:19
-
-
Save markhuge/d4a7551db24a6ed7ceba7548c3e332b9 to your computer and use it in GitHub Desktop.
In case I die: Cynthia's staff
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 "FastLED.h" | |
#define LED_PIN 1 | |
#define LED_TYPE WS2811 | |
#define COLOR_ORDER GRB | |
#define NUM_LEDS 35 | |
CRGB leds[NUM_LEDS]; | |
#define MASTER_BRIGHTNESS 255 | |
// Base background color | |
#define BASE_COLOR CRGB(0,1,1) | |
// Peak color to twinkle up to | |
#define PEAK_COLOR CRGB(127,127,127) | |
// Currently set to brighten up a bit faster than it dims down, | |
// but this can be adjusted. | |
// Amount to increment the color by each loop as it gets brighter: | |
#define DELTA_COLOR_UP CRGB(1,4,4) | |
// Amount to decrement the color by each loop as it gets dimmer: | |
#define DELTA_COLOR_DOWN CRGB(3,2,1) | |
// Chance of each pixel starting to brighten up. | |
// 1 or 2 = a few brightening pixels at a time. | |
// 10 = lots of pixels brightening at a time. | |
#define CHANCE_OF_TWINKLE 1 | |
void setup() { | |
delay(3000); | |
FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); | |
FastLED.setBrightness(MASTER_BRIGHTNESS); | |
InitPixelStates(); | |
} | |
void loop() | |
{ | |
TwinkleMapPixels(); | |
FastLED.show(); | |
FastLED.delay(1); | |
} | |
enum { SteadyDim, GettingBrighter, GettingDimmerAgain }; | |
uint8_t PixelState[NUM_LEDS]; | |
void InitPixelStates() | |
{ | |
memset( PixelState, sizeof(PixelState), SteadyDim); // initialize all the pixels to SteadyDim. | |
fill_solid( leds, NUM_LEDS, BASE_COLOR); | |
} | |
void TwinkleMapPixels() | |
{ | |
for( uint16_t i = 0; i < NUM_LEDS; i++) { | |
if( PixelState[i] == SteadyDim) { | |
// this pixels is currently: SteadyDim | |
// so we randomly consider making it start getting brighter | |
if( random8() < CHANCE_OF_TWINKLE) { | |
PixelState[i] = GettingBrighter; | |
} | |
} else if( PixelState[i] == GettingBrighter ) { | |
// this pixels is currently: GettingBrighter | |
// so if it's at peak color, switch it to getting dimmer again | |
if( leds[i] >= PEAK_COLOR ) { | |
PixelState[i] = GettingDimmerAgain; | |
} else { | |
// otherwise, just keep brightening it: | |
leds[i] += DELTA_COLOR_UP; | |
} | |
} else { // getting dimmer again | |
// this pixels is currently: GettingDimmerAgain | |
// so if it's back to base color, switch it to steady dim | |
if( leds[i] <= BASE_COLOR ) { | |
leds[i] = BASE_COLOR; // reset to exact base color, in case we overshot | |
PixelState[i] = SteadyDim; | |
} else { | |
// otherwise, just keep dimming it down: | |
leds[i] -= DELTA_COLOR_DOWN; | |
} | |
} | |
} | |
} |
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 <Adafruit_NeoPixel.h> | |
#define TOP_PIN 1 // crescent | |
#define GLOBE_PIN 2 // globe | |
#define TAIL_PIN 3 // tail | |
#define BUTTON_PIN 4 // button | |
Adafruit_NeoPixel crescent = Adafruit_NeoPixel(35, TOP_PIN); | |
Adafruit_NeoPixel globe = Adafruit_NeoPixel(2, GLOBE_PIN); | |
Adafruit_NeoPixel tail = Adafruit_NeoPixel(1, TAIL_PIN); | |
uint32_t white = tail.Color(127,127,127,255); | |
uint32_t red = tail.Color(255,0,0); | |
uint8_t buttonState; | |
void setup() { | |
buttonState = digitalRead(BUTTON_PIN); | |
crescent.begin(); | |
globe.begin(); | |
tail.begin(); | |
// Init all pixels to off | |
crescent.show(); | |
globe.show(); | |
tail.show(); | |
} | |
void loop() { | |
for (int i=0;i<crescent.numPixels();i++) { | |
crescent.setPixelColor(i,white); | |
} | |
globe.setPixelColor(0, white); | |
globe.setPixelColor(1, white); | |
tail.setPixelColor(0, white); | |
crescent.show(); | |
globe.show(); | |
tail.show(); | |
if (buttonState != digitalRead(BUTTON_PIN)) { | |
buttonState = digitalRead(BUTTON_PIN); | |
moonAnimation(); | |
} | |
} | |
void moonAnimation() { | |
fadeOut(crescent); | |
fadeIn(crescent); | |
} | |
void fadeOut (Adafruit_NeoPixel &device) { | |
for (int i=255;i>0;i--) { | |
device.setBrightness(i); | |
device.show(); | |
delay(10); | |
} | |
} | |
void fadeIn (Adafruit_NeoPixel &device) { | |
for (int i=0;i<255;i++) { | |
device.setBrightness(i); | |
device.show(); | |
delay(10); | |
} | |
} | |
void crescentStarlight() { | |
for (int i=0; i<crescent.numPixels(); i++) { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment