Thalia Kennedy
Published

Lane Tech HS - Skating Weather Determination

This project will determine whether the temperature outside is suitable or not to go out and go skateboarding.

IntermediateFull instructions provided2 hours143
Lane Tech HS - Skating Weather Determination

Things used in this project

Hardware components

Argon
Particle Argon
×1
RGB LED
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Open Weather API

Story

Read more

Schematics

Project Schematics

Code

Skating Weather Code

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

StaticJsonDocument<1308> doc;

int redPin = 3;
int greenPin = 5;
int bluePin = 6;

double  currentTemp = 0.0;
double feelsLike = 0.0;
String weatherType = "";

void setup()
{
    // Subscribe to the webhook response event
    Particle.subscribe("hook-response/skatingWeather", multiValueHandler);
    Serial.begin(9600);
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);  
}

void multiValueHandler(const char *event, const char *data){
    
    String dataStr = String(data);
    
    char strBuffer[40] = "";
    dataStr.toCharArray(strBuffer, 40);
    
    String firstToken = strtok(strBuffer, ",");
    
    Serial.println(data);
    Serial.println("Temperature: " + firstToken);
    
    String secondToken = strtok(NULL, ",");
    Serial.println("Feels like: " + secondToken);
    
    String thirdToken = strtok(NULL, ",");
    
    String fourthToken = strtok(NULL, ",");
    
    Serial.println("The weather today: " + thirdToken + ", " + fourthToken);
    
    currentTemp = atof(firstToken); 
    feelsLike = atof(secondToken);
    weatherType = thirdToken;
}

void loop()
{
    // Get some data
    String data = String(10);
    // Trigger the integration
    Particle.publish("skatingWeather", data, PRIVATE);
    // Wait 10 seconds
    delay(10000);
    
    String rain = "Rain";
    String snow = "Snow";
    
    if(currentTemp < 25 || strcmp(weatherType, rain) == 0 || strcmp(weatherType, snow) == 0 || feelsLike < 25){
        setColor(255,0,0); //red. no good for skating bro
    }
    else if(currentTemp > 45){
        setColor(0,255,0); //green. you are good to go!
    }
    else{
        setColor(255,255,0); //yellow. you might wanna feel outside before you go. it's up to you.
    }
}

void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

Credits

Thalia Kennedy

Thalia Kennedy

3 projects • 2 followers

Comments

Add projectSign up / Login