Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// This #include statement was automatically added by the Particle IDE.
#include "neopixel.h"

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int switchPin = D3;

int takePeriod = 3 * 1000;
int alertPeriod = 3 * 1000;


// store the connect state
bool connect = false;


void setup(){;

pinMode( switchPin , INPUT_PULLUP); // sets pin as input

strip.begin();

Particle.subscribe( "doPairedPublish", handleConnection );
}

// store the brightness in a new variable
void hubShow(){
    Particle.publish( "doPairedPublish" );
}

void loop(){
    int switchState = digitalRead( switchPin );
    // the hub function is activated
    // the bottle is closed
    if( switchState == HIGH ){
        // after a certain period, change color to yellow to remind the user to take the pill
        delay(takePeriod);
        hubShow();
        red();
    }else{
      white();
	}
}

void yellow(){
    	    
            uint32_t c = strip.Color(255,255,0); // yellow
            for( int i = 0; i < strip.numPixels(); i++ ){
                strip.setPixelColor(i, c);  
                }
            strip.show();
            // // If the user does not take the pill after the 1st reminder for a certain period, the led will turn into red to realert
            // delay(alertPeriod);
            // changeColor();
        // the bottle is open
}

void white(){
    // color returns to normal white
            uint32_t c = strip.Color(255,255,255); // white
            for( int i = 0; i < strip.numPixels(); i++ ){
                strip.setPixelColor(i, c); // set a color 
                }
            strip.show();
}    

void red(){    //function to change the color
    // delay(takePeriod);
    uint32_t c = strip.Color(255,0,0); // red
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c); 
        }
    strip.show();

}

void handleConnection( const char *event, const char *data){
    // delay(takePeriod);
   red();
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0