#include "neopixel/neopixel.h" #include "SparkTime/SparkTime.h" #include "math.h" UDP UDPClient; SparkTime rtc; #define PIXEL_COUNT 32 #define PIXEL_PIN D0 #define PIXEL_TYPE WS2812B #define RAINBOW_MASK 0x3F #define RAINBOW_LEN 64 #define LightPin A0 // This is the analog pin the light sensor is connected to. unsigned long currentTime; String timeStr; unsigned long previousMillis = 0; // This is used in the delay portion. const long interval = 120000; // This is the length of the delay put into the code. int fade_steps = 250; // This is the number of steps used to fade the LEDs. int red = 0; // This is the initial red LED value. int green = 0; // This is the initial green LED value. int blue = 0; // This is the initial blue LED value. boolean LED_Status = false; // This is the status of whether the LEDs are turned on. On = true, off = false. int counter = 0; // This is used for the NeoPixel rainbow effect for my birthday. byte pulse_rainbow[RAINBOW_LEN] = {0,12,25,38,51,64,76,89,102,115, 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 128,128,128,128,128,115,102,89,76,64,51,38,25,12,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int display1_pin = 14; // This is the first meter output pin. int display2_pin = 15; // This is the second meter output pin. int display3_pin = 16; // This is the third meter output pin. int display4_pin = 17; // This is the fourth meter output pin. int current_temp_voltage = 0; // This is a variable to hold the output voltage for the gauge. int max_temp_voltage = 0; // This is a variable to hold the output voltage for the gauge. int today_weather_voltage = 0; // This is a variable to hold the output voltage for the gauge. int tomorrow_weather_voltage = 0; // This is a variable to hold the output voltage for the gauge. Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); void setup() { strip.begin(); strip.show(); // Initialize all LED pixels to 'off' rtc.begin(&UDPClient, "north-america.pool.ntp.org"); rtc.setUseDST(true); rtc.setTimeZone(-5); // GMT offset Serial.begin(115200); pinMode(display1_pin, OUTPUT); // sets the pin as output pinMode(display2_pin, OUTPUT); // sets the pin as output pinMode(display3_pin, OUTPUT); // sets the pin as output pinMode(display4_pin, OUTPUT); // sets the pin as output // Listen for the hook response Spark.subscribe("hook-response/get_weather", gotWeatherData, MY_DEVICES); } void loop() { currentTime = rtc.now(); Particle.process(); // The code below checks to see if it is between certain hours. if (atoi(rtc.hourString(currentTime)) > 6 && atoi(rtc.hourString(currentTime)) < 22) { // Change the hours to match the time the device should be turned on. special_date(); LED_Status = true; } else { if(LED_Status = true) { colorAll(strip.Color(0, 0, 0), 50); // Turn off the NeoPixel LEDS. LED_Status = false; } } unsigned long currentMillis = millis(); Particle.process(); if(currentMillis - previousMillis >= interval) { previousMillis = currentMillis; Spark.publish("get_weather"); // Publish the event that will trigger the Webhook Particle.process(); } } // This function gets called when weather data comes in. void gotWeatherData(const char *name, const char *data) { String str = String(data); char strBuffer[500] = ""; str.toCharArray(strBuffer, 500); int currenttemp = atoi(strtok(strBuffer, "\"~")); int tempmaxtoday = atoi(strtok(NULL, "~")); String forecasttoday = (strtok(NULL, "~")); int tempmaxtomorrow = atoi(strtok(NULL, "~")); String forecasttomorrow = (strtok(NULL, "~")); Particle.process(); Serial.print("Current Temperature: "); Serial.println(currenttemp); current_temp_voltage = map(currenttemp, -20, 100, 0, 255); analogWrite(display1_pin, current_temp_voltage); Serial.print("Maximum Temp Today: "); Serial.println(tempmaxtoday); max_temp_voltage = map(tempmaxtoday, -20, 100, 0, 255); analogWrite(display2_pin, max_temp_voltage); Serial.print("Today's Weather: "); Serial.println(forecasttoday); if (forecasttoday == "clear-day"){ analogWrite(display3_pin, 0);} else if (forecasttoday == "clear-night"){ analogWrite(display3_pin, 28.3);} else if (forecasttoday == "wind"){ analogWrite(display3_pin, 56.6);} else if (forecasttoday == "cloudy"){ analogWrite(display3_pin, 84.9);} else if (forecasttoday == "rain"){ analogWrite(display3_pin, 113.2);} else if (forecasttoday == "snow"){ analogWrite(display3_pin, 141.5);} else if (forecasttoday == "sleet"){ analogWrite(display3_pin, 169.8);} else if (forecasttoday == "fog"){ analogWrite(display3_pin, 198.1);} else if (forecasttoday == "party-cloudy-day"){ analogWrite(display3_pin, 226.4);} else if (forecasttoday == "partly-cloudy-night"){ analogWrite(display3_pin, 255);} else analogWrite(display3_pin, 0); Serial.print("Forecast Tomorrow: "); Serial.println(forecasttomorrow); if (forecasttomorrow == "clear-day"){ analogWrite(display4_pin, 0);} else if (forecasttomorrow == "clear-night"){ analogWrite(display4_pin, 28.3);} else if (forecasttomorrow == "wind"){ analogWrite(display4_pin, 56.6);} else if (forecasttomorrow == "cloudy"){ analogWrite(display4_pin, 84.9);} else if (forecasttomorrow == "rain"){ analogWrite(display4_pin, 113.2);} else if (forecasttomorrow == "snow"){ analogWrite(display4_pin, 141.5);} else if (forecasttomorrow == "sleet"){ analogWrite(display4_pin, 169.8);} else if (forecasttomorrow == "fog"){ analogWrite(display4_pin, 198.1);} else if (forecasttomorrow == "party-cloudy-day"){ analogWrite(display4_pin, 226.4);} else if (forecasttomorrow == "partly-cloudy-night"){ analogWrite(display4_pin, 255);} else analogWrite(display4_pin, 0); } // Set all pixels in the strip to a solid color, then wait (ms) void colorAll(uint32_t c, uint8_t wait) { uint16_t i; for(i=0; i