// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
int photoCell = A0;
bool state = false;
int redValue = 255;
int greenValue = 255;
int blueValue = 255;
#define PIXEL_COUNT 1
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int timeToBus = 0;
const char *printData = 0;
int photoCellReading = 0;
int ledBrightness = 0;
void setup() {
strip.begin();
Particle.subscribe("hook-response/BusTime", myHandler, MY_DEVICES);
Particle.variable("timeToBus", timeToBus);
Particle.variable("light", &photoCellReading, INT);
}
void loop() {
int photoCellReading = analogRead(photoCell);
ledBrightness = map(photoCellReading, 0, 4095, 0, 255);
if (ledBrightness > 20){
state = true;
}
else {
state = false;
setRGBColor( 0,0,0);
}
if( state == true )
{
Particle.publish( "BusTime" );
delay( 5000 );
if(timeToBus > 10)
{
setRGBColor( 0,100,0 );
}
else if(timeToBus <= 10 && timeToBus > 5)
{
setRGBColor( 100,100,0 );
}
else if(timeToBus <= 5)
{
setRGBColor( 100,0,0 );
delay(300);
setRGBColor( 0,0,0 );
delay(300);
setRGBColor( 100,0,0 );
}
}
}
void setRGBColor( int r, int g, int b ){
redValue = r;
greenValue = g;
blueValue = b;
strip.setPixelColor(0, redValue, greenValue, blueValue);
strip.show();
}
void myHandler(const char *event, const char *data) {
// Handle the integration respo
String busPrediction = String( data );
if( busPrediction.equals( "DUE" ) ){
timeToBus = 0;
}
else{
timeToBus = busPrediction.toInt();
}
}
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. .