Last active
March 7, 2016 17:53
-
-
Save mock-turtle/be0fa63a1f409bdd034f to your computer and use it in GitHub Desktop.
Updated cloud code. Patterns should play on button press.
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
//import the necessary libraries | |
#include "FastLED.h" | |
#include "IRremote.h" | |
//define some variables | |
#define LEDPIN 6 | |
#define RECV_PIN 3 | |
#define LED_TYPE NEOPIXEL | |
#define NUM_LEDS 15 | |
#define BRIGHTNESS 200 | |
CRGB leds[NUM_LEDS]; | |
CRGB endclr; | |
CRGB midclr; | |
//set up IR receiver information | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
//<————————————————————————————SETUP————————————————————————————> | |
void setup() { | |
//begin serial communication | |
Serial.begin(9600); | |
//sanity delay | |
delay(3000); | |
//start the receiver | |
irrecv.enableIRIn(); | |
//set up LED strip information | |
FastLED.addLeds<LED_TYPE,LEDPIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); | |
FastLED.setBrightness(BRIGHTNESS); | |
} | |
//<—————————————————————————LOOP———————————————————————————————> | |
void loop() { | |
//decode IR results | |
if (irrecv.decode(&results)) { | |
//declare changing variables | |
uint8_t gHue = 0; | |
uint8_t colour = beatsin8(130, 0, 150); | |
uint8_t spd = beatsin8(10,0,255); | |
uint8_t dot = beatsin8(50, 0, NUM_LEDS); | |
uint8_t beat = beatsin8( 70, 64, 255); | |
uint8_t beat2 = beatsin8( 50, 64, 255); | |
//<——————————————————BUTTON FUNCTIONS—————————————————————————> | |
//power button = plain white | |
if (results.value == 0xFD00FF){ | |
fill_solid(leds,NUM_LEDS,CRGB::White); | |
} | |
//vol+ = brightness full | |
if (results.value == 0xFD807F){ | |
FastLED.setBrightness(255); | |
} | |
//vol- = brightness down | |
if (results.value == 0xFD906F){ | |
fadeLightBy(leds, NUM_LEDS, 30); | |
} | |
//play/pause = cycles through colour list | |
if (results.value == 0xFDA05F) { | |
fill_solid(leds, NUM_LEDS, CHSV(colour, 255, 150)); | |
} | |
//left = CUSTOM GRADIENT (goes from a blue-purple gradient to pink-green. change the colour names below for a new pattern) | |
if (results.value == 0xFD20DF) { | |
endclr = blend(CRGB::Blue, CRGB::Pink, spd); | |
midclr = blend(CRGB::Purple, CRGB::Green, spd); | |
fill_gradient_RGB(leds, 0, endclr, NUM_LEDS/2, midclr); | |
fill_gradient_RGB(leds, NUM_LEDS/2+1, midclr, NUM_LEDS, endclr); | |
FastLED.show();} | |
//right = CUSTOM SOLID COLOUR (change colour name below to your favourite colour!) | |
if (results.value == 0xFD609F) { | |
fill_solid(leds,NUM_LEDS,CRGB::Purple); | |
} | |
//func/stop = xmas | |
if (results.value == 0xFD40BF) { | |
leds[dot] = CRGB::Red; | |
leds[dot+1] = CRGB::Green; | |
} | |
//up = bpm | |
if (results.value == 0xFD50AF) { | |
CRGBPalette16 palette = PartyColors_p; | |
for( int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));} | |
} | |
//down = fire | |
if (results.value == 0xFD10EF) { | |
CRGBPalette16 palette = HeatColors_p; | |
for( int i = 0; i < NUM_LEDS; i++) { | |
leds[i] = ColorFromPalette(palette, gHue+(i*2), beat2-gHue+(i*10)); } | |
} | |
//eq = rainbow | |
if (results.value == 0xFDB04F) { | |
fill_rainbow( leds, NUM_LEDS-3, gHue, 7); | |
leds[12] = CRGB::Blue; | |
leds[13] = CRGB::Purple; | |
leds[14] = CRGB::Purple; | |
} | |
//st/rept = rainbow w stars | |
if (results.value == 0xFD708F) { | |
fill_rainbow( leds, NUM_LEDS-3, gHue, 7); | |
leds[12] = CRGB::Blue; | |
leds[13] = CRGB::Purple; | |
leds[14] = CRGB::Purple; | |
addGlitter(70); | |
} | |
// 0 = sun | |
if (results.value == 0xFD30CF) { | |
endclr = blend(CRGB::Yellow, CHSV(0,0,170), spd); | |
midclr = blend(CHSV(0,0,150), CRGB::Yellow, spd); | |
fill_gradient_RGB(leds, 0, endclr, NUM_LEDS/2, midclr); | |
fill_gradient_RGB(leds, NUM_LEDS/2+1, midclr, NUM_LEDS, endclr); | |
} | |
// 1 = sunrise (pink & blue) | |
if (results.value == 0xFD08F7) { | |
fill_gradient(leds, 0, CHSV(160,185,210), NUM_LEDS-1, CHSV(237,141,255)); | |
} | |
// 2 = sunset (orange & blue) | |
if (results.value == 0xFD8877) { | |
fill_gradient_RGB(leds, 0, CHSV(150,255,200), NUM_LEDS-1, CHSV(25,255,255)); | |
} | |
// 3 = sunrise to sunset | |
if (results.value == 0xFD48B7) { | |
endclr = blend(CHSV(150,255,210), CHSV(160,185,200), spd); | |
midclr = blend(CHSV(25,255,255), CHSV(237,141,255), spd); | |
fill_gradient_RGB(leds, 0, endclr, NUM_LEDS/2, midclr); | |
fill_gradient_RGB(leds, NUM_LEDS/2+1, midclr, NUM_LEDS, endclr); | |
} | |
// 4 = dusk | |
if (results.value == 0xFD28D7) { | |
fill_gradient_RGB(leds, 0, CHSV(160,255,150), NUM_LEDS-1, CHSV(180,230,80)); | |
} | |
// 5 = starry night | |
if (results.value == 0xFDA857) { | |
fill_gradient_RGB(leds, 0, CHSV(160,255,150), NUM_LEDS-1, CHSV(180,230,80)); | |
addGlitter(80); | |
} | |
// 6 = rain | |
if (results.value == 0xFD6897) { | |
fadeToBlackBy( leds, NUM_LEDS, 30); | |
int pos = random16(NUM_LEDS); | |
leds[pos] = CHSV(135,80,200); | |
} | |
// 7 = acid rain | |
if (results.value == 0xFD18E7) { | |
fadeToBlackBy( leds, NUM_LEDS, 130); | |
int pos = random16(NUM_LEDS); | |
leds[pos] = CRGB::Green; | |
} | |
// 8 = snow | |
if (results.value == 0xFD9867) { | |
fadeToBlackBy( leds, NUM_LEDS, 30); | |
addGlitter(50); | |
} | |
// 9 = storm | |
if (results.value == 0xFD58A7) { | |
fadeToBlackBy( leds, NUM_LEDS, 30); | |
fill_solid(leds,NUM_LEDS,CHSV(0,0,50)); | |
addGlitter(60); | |
lightning(); | |
} | |
//rotating base colour used by many of the patterns | |
FastLED.delay(1000/120); | |
EVERY_N_MILLISECONDS( 20 ) { gHue++; } | |
FastLED.show(); | |
irrecv.resume(); // Receive the next value | |
} | |
} | |
//<——————————————————————EXPANDED FUNCTIONS————————————————————> | |
void addGlitter( fract8 chanceOfGlitter) | |
{if( random8() < chanceOfGlitter) { | |
leds[ random16(NUM_LEDS) ] += CRGB::White;} | |
} | |
void lightning () | |
{EVERY_N_MILLISECONDS (4000) { | |
uint8_t i = beatsin8(6, 0, 255); | |
fill_solid(leds, NUM_LEDS, CHSV(160, 10, i)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment