Created
March 15, 2016 20:38
-
-
Save morphatic/477ab376001cff17f876 to your computer and use it in GitHub Desktop.
Arduino code for Particle Photon to control NeoPixel light shows.
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
// import the FastLED Library for controlling NeoPixels | |
#include "FastLED/FastLED.h" | |
FASTLED_USING_NAMESPACE; | |
// setup the LED ring which has 24 LEDs and | |
// communicates via pin D6 | |
#define NUM_LEDS 24 | |
#define LED_PIN D6 | |
CRGB leds[NUM_LEDS]; | |
// global variables | |
String currentShow = "solidColor"; | |
int currentColor = 0x0000FF; // defaults to blue | |
void setup() { | |
// set up the ring | |
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS); | |
// variables accessible from our app | |
Particle.variable("show", currentShow); | |
Particle.variable("color", currentColor); | |
// basic controls to set the above variables | |
Particle.function("setShow", setShow); | |
Particle.function("setColor", setColor); | |
} | |
void loop() { | |
if (currentShow=="solidColor") { | |
solidColor(); | |
} else if (currentShow=="rainbow") { | |
rainbow(); | |
} else if (currentShow=="strobe") { | |
strobe(); | |
} else if (currentShow=="pulse") { | |
pulse(); | |
} | |
} | |
/* | |
|-------------------------------------------------------------------------- | |
| Basic controls | |
|-------------------------------------------------------------------------- | |
| | |
| Functions for turning the LEDs and bubbles on and off. | |
| | |
*/ | |
int setShow(String show) { | |
currentShow = show; | |
return 1; | |
} | |
int setColor(String color) { | |
currentColor = strtol(color, NULL, 16); | |
return 1; | |
} | |
/* | |
|-------------------------------------------------------------------------- | |
| Light Shows | |
|-------------------------------------------------------------------------- | |
| | |
| Each function below defines a light show. | |
| | |
*/ | |
void solidColor() { | |
fill_solid(leds, NUM_LEDS, currentColor); | |
FastLED.show(); | |
} | |
void rainbow() { | |
static uint8_t hue = 0; | |
static uint8_t delta = 3; | |
fill_solid(leds, NUM_LEDS, CHSV(hue, 187, 255)); | |
FastLED.show(); | |
hue += delta; | |
delay(100); | |
} | |
void strobe() { | |
fill_solid(leds, NUM_LEDS, currentColor); | |
FastLED.show(); | |
delay(50); | |
fill_solid(leds, NUM_LEDS, CRGB::Black); | |
FastLED.show(); | |
delay(50); | |
} | |
void pulse() { | |
static uint8_t brightness = 0; | |
fill_solid(leds, NUM_LEDS, CHSV(0, 0, cubicwave8(brightness))); | |
FastLED.show(); | |
delay(20); | |
brightness += 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment