// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#include "neopixel.h"
#define PIXEL_PIN D3
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
bool warm;
float limit =72;
float temperature;
void getData()
{
// Publish an event to trigger the webhook
Particle.publish( "get-forecast" );
}
int get_compare(String args){
float set_tmp = String(args).toFloat();
limit = set_tmp;
return 1;
}
void setup() {
strip.begin();
strip.show();
Particle.function("get_compare", get_compare);
Particle.subscribe("hook-response/get-forecast", handleForecastReceived );
getData();
}
//Webhook functions
// This function will handle data received back from the webhook
void handleForecastReceived(const char *event, const char *data) {
// Handle the integration response
String receivedStr = String( data );
int loc1 = 0;
loc1 = receivedStr.indexOf("~");
String temperature_str = receivedStr.substring(0,loc1);
float tmp = String(temperature_str).toFloat();
double humidity = (double) String(receivedStr.substring(loc1+1)).toFloat();
//debugging string-- displays the temperature
Particle.publish(receivedStr);
temperature = tmp;
// if (temperature > (double)72){
// warm = true;
// }
// else{
// warm = false;
// }
}
void cooler_fade(){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, 0, 100, 100); // set a color
strip.show();
delay( 100 );
}
for (int j = 0; j < 3; j++){
for( int k = 0; k <256; k++ ){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, 0, k/3, k/2); // set a color
}
strip.show();
delay( 10 );
}
for( int k = 255; k >=0; k-- ){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, 0, k/3, k/2 ); // set a color
}
strip.show();
delay( 10 );
}
}
for( int i = 0; i < strip.numPixels(); i++ ){
if (i>0){
strip.setPixelColor(i-1, 0, 0, 0); // set a color
}
strip.setPixelColor(i, 0, 100, 100); // set a color
strip.show();
delay( 100 );
}
}
void warmer_fade(){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, 235, 52, 100); // set a color
strip.show();
delay( 100 );
}
for (int j = 0; j < 3; j++){
for( int k = 0; k <256; k++ ){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, k/2, 0, k/3); // set a color
}
strip.show();
delay( 10 );
}
for( int k = 255; k >=0; k-- ){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, k/2, 0, k/3); // set a color
}
strip.show();
delay( 10 );
}
}
for( int i = 0; i < strip.numPixels(); i++ ){
if (i>0){
strip.setPixelColor(i-1, 0, 0, 0); // set a color
}
strip.setPixelColor(i, 235, 52, 155); // set a color
strip.show();
delay( 100 );
}
}
void loop() {
// This makes it go brighter and then dim back down
if (temperature > limit){
warmer_fade();
}
else{
cooler_fade();
}
// if(warm){
// warmer_fade();
// }
// else{
// cooler_fade();
// }
}
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. .