// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h> // Neopixel Library
#define PIXEL_PIN D5
#define PIXEL_COUNT 1
#define PIXEL_TYPE WS2812B
int i=0;
bool event1 ; // home chip
bool event2 ; // work chip
bool event3 ; // home location
bool event4 ; // work
String dataIn;
int caseState;
const bool isInterrupt = true;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup() {
Serial.begin(9600);
Particle.subscribe("at_home", atHome, MY_DEVICES);
Particle.subscribe("call_mom", callMom, MY_DEVICES);
Particle.subscribe("email_at_work", atWork, MY_DEVICES);
Particle.subscribe("kenz_location", fakeLocation, MY_DEVICES);
// Particle.subscribe("location_work", myHandle4, MY_DEVICES);
pixels.begin();
}
void loop() {
switch (caseState) {
case 0:
pixelOff();
break;
case 1: // Work Location
pixelWork();
if (event2 == true){
pixelEmail();
}
break;
case 2: // Home Location
pixelHome();
if (event1 == true){
pixelNotebook();
}
if (event3 == true){
pixelMom();
}
break;
default:
pixelOff();
break;
}
/*
if (( event1 == true) && (event3 == true)){
pixelHome();
} else if (( event2 == true) && (event4 == true)){
pixelWork();
} else {
pixelOff();
}
*/
}
void atHome(const char *event, const char *data){ // listening for at home reminder
if(strcmp(data, "remember_me")==0){
event1 = true;
} else {
event1 = false;
}
}
void atWork(const char *event, const char *data){ // listenging for at work to send email
if(strcmp(data, "send_mail")==0){
event2 = true;
} else{
event2 = false;
}
}
void callMom(const char *event, const char *data){ // listenging for at work to send email
if(strcmp(data, "soonish")==0){
event3 = true;
} else{
event3 = false;
}
}
void fakeLocation(const char *event, const char *data){ // listening for fake location data HOME
dataIn = data;
dataIn.toLowerCase();
//-----DEBUGGING-----
// Serial.print(data);
// Serial.print(", ");
// Serial.println(dataIn);
if(dataIn == "work"){
caseState = 1;
} else if(dataIn == "home"){
caseState = 2;
} else if(dataIn == "clear"){
caseState = 0;
}
}
void pixelGreen(){
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); //(GREEN, RED, BLUE)
pixels.show();
}
void pixelOff(){
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); //(GREEN, RED, BLUE)
pixels.show();
}
void pixelHome(){
pixels.setPixelColor(0, pixels.Color(255,0,165));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
}
void pixelWork(){
pixels.setPixelColor(0, pixels.Color(0, 255, 106));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
}
void pixelMom(){
pixels.setPixelColor(0, pixels.Color(0,168,206)); //(GREEN, RED, BLUE)
pixels.show();
delay(1000);
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
}
void pixelNotebook(){
pixels.setPixelColor(0, pixels.Color(255,0,40)); //(GREEN, RED, BLUE)
pixels.show();
delay(1000);
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
}
void pixelEmail(){
pixels.setPixelColor(0, pixels.Color(0,255,40)); //(GREEN, RED, BLUE)
pixels.show();
delay(1000);
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(500);
}
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. .