Accelerometer
#include "neopixel.h"
#define PIXEL_PIN D0
#define PIXEL_COUNT 16
#define PIXEL_TYPE SK6812RGBW
Adafruit_NeoPixel ring = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
Serial.begin(9600);
// ring.setBrightness(55);
ring.begin();
ring.show();
//rainforest
Particle.subscribe("diot2017/musical_plates/activity", activity);
Particle.subscribe("eatingend", finishedeating, "310039000f51353338363333");
//space
Particle.subscribe("space_eatingend", spacefinishedeating, "310039000f51353338363333");
}
void loop() {
}
void activity(const char *event,const char *data) {
String activity = data;
if (activity == "drink") {
changeColor(ring.Color(0, 0, 0, random(200, 256)));
delay(random(50,70));
changeColor(ring.Color(0, 0, 0, random(100, 200)));
delay(random(50,70));
changeColor(ring.Color(0, 0, 0, random(200, 256)));
delay(random(600,800));
changeColor(ring.Color(0, 0, 0, 0));
delay(random(200,300));
changeColor(ring.Color(0, 0, 0, random(100, 200)));
delay(random(50,70));
changeColor(ring.Color(0, 0, 0, random(200, 256)));
delay(random(50,70));
changeColor(ring.Color(0, 0, 0, random(100, 200)));
delay(random(50,70));
changeColor(ring.Color(0, 0, 0, random(200, 256)));
delay(random(50,70));
changeColor(ring.Color(0, 0, 0, 256));
delay(random(150,300));
changeColor(ring.Color(0, 0, 0, 0));
delay(random(250,350));
changeColor(ring.Color(0, 0, 0, random(100, 200)));
delay(random(20,50));
changeColor(ring.Color(0, 0, 0, 230));
delay(random(200,300));
for(int i = 230; i >= 0; i -= 20) {
changeColor(ring.Color(0,0,0,i));
delay(1);
}
}
else if (activity == "space_drink") {
for(int j=0; j<256; j++) {
for(uint16_t i=0; i<ring.numPixels(); i++) {
ring.setPixelColor(i, ring.Color(0, 0, 0, 255) );
ring.show();
delay(85);
}
changeColor(ring.Color(0, 0, 0, 0));
delay(300);
changeColor(ring.Color(0, 0, 0, 255));
delay(1000);
changeColor(ring.Color(0, 0, 0, 0));
off();
}
}
else {
off();
}
}
void finishedeating(const char *event,const char *data) {
hueChase(ring.Color(127, 100, 0), 50); // Lime Green
hueChase(ring.Color(80, 0, 127), 50); // Cyan
hueChase(ring.Color(127, 0, 0), 50); // Green
hueChase(ring.Color(127, 100, 0), 50); // Lime Green
hueChase(ring.Color(80, 0, 127), 50); // Cyan
hueChase(ring.Color(127, 0, 0), 50); // Green
off();
}
void spacefinishedeating(const char *event, const char *data) {
greencolor();
redcolor();
bluecolor();
}
void greencolor(){
for(int i = 0; i <= 240; i += 20) {
changeColor(ring.Color(i,0,0,0));
delay(1);
}
delay(500);
for(int i = 240; i >= 0; i -= 20) {
changeColor(ring.Color(i,0,0,0));
delay(1);
}
}
void redcolor(){
for(int i = 0; i <= 240; i += 20) {
changeColor(ring.Color(0,i,0,0));
delay(1);
}
delay(500);
for(int i = 240; i >= 0; i -= 20) {
changeColor(ring.Color(0,i,0,0));
delay(1);
}
}
void bluecolor(){
for(int i = 0; i <= 240; i += 20) {
changeColor(ring.Color(0,0,i,0));
delay(1);
}
delay(500);
for(int i = 240; i >= 0; i -= 20) {
changeColor(ring.Color(0,0,i,0));
delay(1);
}
}
void hueChase(uint32_t c, uint8_t wait) {
for (int j=0; j<5; j++) {
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < ring.numPixels(); i=i+3) {
ring.setPixelColor(i+q, c);
}
ring.show();
delay(wait);
for (uint16_t i=0; i < ring.numPixels(); i=i+3) {
ring.setPixelColor(i+q, 0);
}
}
}
}
void off() {
changeColor(ring.Color(0, 0, 0, 0));
}
void changeColor(uint32_t color) {
for(uint16_t i=0; i < ring.numPixels(); i++) {
ring.setPixelColor(i, color);
ring.show();
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .