-
-
Save fvdbosch/ff9d69a2b103abe61b6908884610ea12 to your computer and use it in GitHub Desktop.
IoT Tower Light
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
/* | |
* This is a minimal example, see extra-examples.cpp for a version | |
* with more explantory documentation, example routines, how to | |
* hook up your pixels and all of the pixel types that are supported. | |
* | |
*/ | |
#include "application.h" | |
#include "neopixel/neopixel.h" | |
SYSTEM_MODE(AUTOMATIC); | |
// IMPORTANT: Set pixel COUNT, PIN and TYPE | |
#define PIXEL_PIN D2 | |
#define PIXEL_COUNT 12 | |
#define PIXEL_TYPE WS2812B | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); | |
int animation = 0; | |
void setup() | |
{ | |
strip.begin(); | |
strip.show(); // Initialize all pixels to 'off' | |
Particle.subscribe("animation", myHandler); | |
} | |
void loop() | |
{ | |
if(animation == 1) { | |
siren(50); | |
} | |
else if(animation == 2) { | |
pulse(10); | |
} | |
else if(animation == 3) { | |
blink(500); | |
} | |
else if(animation == 4) { | |
fill(); | |
} | |
else { | |
clear(); | |
} | |
} | |
void myHandler(const char *event, const char *data) { | |
animation = atoi(data); | |
} | |
void siren(uint8_t wait) { | |
uint16_t i, j; | |
for(i=0; i<6; i++) { | |
for(j=0; j<12; j++) { | |
strip.setPixelColor(j, strip.Color(0, 0, 0)); | |
} | |
strip.setPixelColor(i, strip.Color(255, 0, 0)); | |
strip.setPixelColor(i+1, strip.Color(255, 0, 0)); | |
strip.setPixelColor(i+2, strip.Color(255, 0, 0)); | |
strip.setPixelColor(i+6, strip.Color(255, 0, 0)); | |
strip.setPixelColor(i+7, strip.Color(255, 0, 0)); | |
strip.setPixelColor(i+8, strip.Color(255, 0, 0)); | |
strip.show(); | |
delay(wait); | |
} | |
} | |
void fill() { | |
uint16_t i; | |
for(i=0; i<12; i++) { | |
strip.setPixelColor(i, strip.Color(255, 0, 0)); | |
} | |
strip.show(); | |
} | |
void clear() { | |
uint16_t i; | |
for(i=0; i<12; i++) { | |
strip.setPixelColor(i, strip.Color(0, 0, 0)); | |
} | |
strip.show(); | |
} | |
void pulse(uint8_t wait) { | |
uint16_t i, j; | |
for(j=0; j<256; j++) { | |
for(i=0; i<12; i++) { | |
strip.setPixelColor(i, strip.Color(j, 0, 0)); | |
} | |
strip.show(); | |
delay(wait); | |
} | |
for(j=255; j>0; j--) { | |
for(i=0; i<12; i++) { | |
strip.setPixelColor(i, strip.Color(j, 0, 0)); | |
} | |
strip.show(); | |
delay(wait); | |
} | |
} | |
void blink(uint16_t wait) { | |
uint16_t i, j; | |
for(i=0; i<12; i++) { | |
strip.setPixelColor(i, strip.Color(0, 0, 0)); | |
} | |
strip.show(); | |
delay(wait); | |
for(i=0; i<12; i++) { | |
strip.setPixelColor(i, strip.Color(255, 0, 0)); | |
} | |
strip.show(); | |
delay(wait); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment