Trisha
Published

Beach Box

Structural embodiment and artistic representation of Chicago Data on beach weather.

IntermediateFull instructions provided13
Beach Box

Things used in this project

Hardware components

SparkFun Solder-able Breadboard - Mini
SparkFun Solder-able Breadboard - Mini
×1
Photon 2
Particle Photon 2
×1
55g Servo
×1
LED Strip, NeoPixel Digital RGB
LED Strip, NeoPixel Digital RGB
×1
DC Power Cord 5V Power Supply
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Code

Code for Entire Project

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

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

JsonDocument doc;

String strJSON = "";

int count = 0;
 
int temp;

int rain;

int direction;

int speed;

int solar;

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

Servo myServo; 


#define PIXEL_PIN1 SPI1
#define PIXEL_PIN2 SPI
#define PIXEL_COUNT 41
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip1(4, PIXEL_PIN1, PIXEL_TYPE);
Adafruit_NeoPixel strip2(PIXEL_COUNT, PIXEL_PIN2, PIXEL_TYPE);

uint32_t green  = strip1.Color(0, 255, 0);
uint32_t yellow = strip1.Color(255, 255, 0);
uint32_t red    = strip1.Color(255, 0, 0);
uint32_t blue = strip1.Color(0, 0, 255);


void setup()
{  
    Serial.begin(9600);
    while(Particle.disconnected()) ;
    
   myServo.attach(D1);
    
    
    
    
   myServo.write(0); 
   
    
    
    strip1.begin();
    strip2.begin();

    for (int i = 0; i < 4; i++) 
    {
        strip1.setPixelColor(i, yellow);
    }
    
    for (int i = 0; i < 41; i++) 
    {
        strip2.setPixelColor(i, red);
    }

    strip1.show();
    strip2.show();
    delay(150);
  
    
    
       
    
    
    

    Particle.subscribe("hook-response/beachData", handleResponse);
    
    Serial.println("Setup has ended!");
}


void loop()
{

        if (b < 0) b = 0;
        if (b > 255) b = 255;
    
        int minBrightness = 20;
        if (b == 0) b = minBrightness;
    
        bool high = (b >= 128);

        {
            for (int cycle = 0; cycle < 5; cycle++)
            {
            
                strip2.setBrightness(b);
                for (int i = 0; i < PIXEL_COUNT; i++)
                    strip2.setPixelColor(i, yellow);
                strip2.show();
                delay(200);
    
                strip2.setBrightness(0);
                for (int i = 0; i < PIXEL_COUNT; i++)
                    strip2.setPixelColor(i, yellow);
                strip2.show();
                delay(200);
            }
    
            strip2.setBrightness(b);
            for (int i = 0; i < PIXEL_COUNT; i++)
                strip2.setPixelColor(i, yellow);
            strip2.show();
    
        }else{
        for (int cycle = 0; cycle < 1; cycle++)
        {
 
            for (int i = b; i > 0; i--)
            {
                strip2.setBrightness(i);
                for (int p = 0; p < PIXEL_COUNT; p++)
                    strip2.setPixelColor(p, yellow);
                strip2.show();
                delay(10);
            }
    
            for (int i = 0; i < b; i++)
            {
                strip2.setBrightness(i);
                for (int p = 0; p < PIXEL_COUNT; p++)
                    strip2.setPixelColor(p, yellow);
                strip2.show();
                delay(10);
            }
        }
        }
    
        
        strip2.setBrightness(b);
        for (int p = 0; p < PIXEL_COUNT; p++)
            strip2.setPixelColor(p, yellow);
        strip2.show();


    int angle = map(direction, 0, 360, 0, 170);

    if (angle < 0) angle = 0;
    if (angle > 170) angle = 170;
    

   for(int pos = 0; pos <= angle; pos++) 
    {                                   
        myServo.write(pos);             
        delay(15);                   }
    
    for(int pos = angle; pos >= 0; pos--)     {
        myServo.write(pos);              
        delay(15);                      
    }
   
}


void handleResponse(const char *event, const char *data)
{
    
    Serial.println("Handler has begun!");
    
    deserializeJson(doc, data);

    JsonObject root_0 = doc[0];
    
     temp = doc[0]["air_temperature"];
     rain = doc[0]["rain_intensity"];
     direction = doc[0]["wind_direction"];
     speed = doc[0]["wind_speed"];
     solar = doc[0]["solar_radiation"];

    
    
    Serial.println(temp);
    Serial.println(rain);
    Serial.println(direction);
    Serial.println(solar);
    
    Serial.println("Ended!");
    

    updateSolar();

}


void updateSolar()
{
    int b = map(solar, 990, 1001, 0, 255);


    if (b < 0) b = 0;
    if (b > 255) b = 255;

    int minBrightness = 20;  

    if (b == 0)
        b = minBrightness;

    strip1.setBrightness(b);

    for (int i = 0; i < strip1.numPixels(); i++)
    {
        strip1.setPixelColor(i, yellow);
    }

    strip1.show();
}

Credits

Trisha
2 projects • 0 followers
Thanks to Valeria .

Comments