Back to Parent

// 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" );
  // triggers response to send GET request to api
}

int get_compare(String args){
    //function that gets user input for the dividing temperature
    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);
  //a float of temerpature is stored to tmp
  float tmp = String(temperature_str).toFloat();
  //humidity is stored to a double
  double humidity = (double) String(receivedStr.substring(loc1+1)).toFloat();
  //DISPLAY TO SCREEN HERE?
  //debugging string-- displays the temperature and humidity to console
  Particle.publish(receivedStr);
  temperature = tmp;
}


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();
 }

}
Click to Expand

Content Rating

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

0