Created
January 22, 2016 04:24
-
-
Save hyshka/820910fed4d231902c39 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
Lunish Moth | |
Flying Canoe Program | |
Author: Bryan Hyshka | |
Modified: 2016/01/21 | |
*/ | |
#include "FastLED.h" | |
FASTLED_USING_NAMESPACE | |
#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) | |
#warning "Requires FastLED 3.1 or later; check github for latest code." | |
#endif | |
// RGB with color temperature strips | |
// R = Cool White, G = Amber, B = Warm White | |
#define LED_TYPE SK6812 | |
#define COLOR_ORDER RGB | |
#define NUM_LEDS 42 | |
#define VOLTS 5 | |
#define MAX_MA 2500 | |
// combine strips into one object | |
CRGBArray<NUM_LEDS> leds; | |
// global vars | |
uint8_t max_bright = 96; | |
#define FRAMES_PER_SECOND 120 | |
#define NUM_TWINKLES 1 | |
#define MIN_TWINKLE_SPEED 2 | |
#define MAX_TWINKLE_SPEED 4 | |
uint8_t twinkle_speed[NUM_TWINKLES]; | |
uint8_t twinklePos[NUM_TWINKLES]; | |
uint8_t twinkle[NUM_TWINKLES]; | |
uint8_t twinkleState[NUM_TWINKLES]; | |
uint8_t twinkleChance[NUM_TWINKLES]; | |
fract8 chanceOfCoolWhite = 40; | |
void setup() { | |
delay(3000); // 3 second delay for recovery | |
// FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_MA); // power management | |
// Multiple strips in one object | |
FastLED.addLeds<LED_TYPE, 3, COLOR_ORDER>(leds, 0, 18).setDither(max_bright < 255); // right - flip this one, 18 px | |
FastLED.addLeds<LED_TYPE, 4, COLOR_ORDER>(leds, 18, 6).setDither(max_bright < 255); // top - start at 18, 6 px | |
FastLED.addLeds<LED_TYPE, 2, COLOR_ORDER>(leds, 24, 18).setDither(max_bright < 255); // left - start at 24, 18px | |
FastLED.setBrightness(max_bright); // limit brightness | |
for (int i = 0; i < NUM_TWINKLES; i++) { | |
// twinklePos[i] = leds(0, 20); | |
twinklePos[i] = 5; | |
twinkleChance[i] = random8(); | |
twinkle_speed[i] = random8(MIN_TWINKLE_SPEED, MAX_TWINKLE_SPEED); | |
} | |
} | |
// Use this function to invert the first strip | |
int IndexToPhysical(int i) { | |
if (i > 17) | |
return(i); | |
else | |
return( 17 - i ); | |
} | |
void loop() { | |
// R = Cool White, G = Amber, B = Warm White | |
for(CRGB & pixel : leds) { pixel = CRGB( 0, beatsin8(6, 8, 192), 0 ); } | |
// how many twinkles? | |
for (int i = 0; i < NUM_TWINKLES; i++) { | |
// is it cool white or warm white? | |
if( twinkleChance[i] < chanceOfCoolWhite) { | |
leds[ IndexToPhysical( twinklePos[i]) ] = CRGB( quadwave8(twinkle[i] += twinkle_speed[i]), 0, 0); // Cool White | |
} else { | |
leds[ IndexToPhysical( twinklePos[i]) ] = CRGB( 0, 0, quadwave8(twinkle[i] += twinkle_speed[i]) ); // Warm White | |
} | |
if (twinkle[i] > 127) { | |
twinkleState[i] = 1; | |
} | |
if (twinkleState[i] == 1 && twinkle[i] == 0) { | |
// twinklePos[i] = random8(0, 20); | |
twinkleState[i] = 0; | |
twinkleChance[i] = random8(); | |
twinkle_speed[i] = random8(MIN_TWINKLE_SPEED, MAX_TWINKLE_SPEED); | |
} | |
} | |
leds(21, 41) = leds(0, 20); | |
FastLED.show(); | |
FastLED.delay(1000/FRAMES_PER_SECOND); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment