Gamya Michael
Published

Physical Computing Lab Sculpture Project

A sculpture portraying the struggle of gun violence on adolescence, by using an API to access data and portraying accordingly.

IntermediateShowcase (no instructions)59
Physical Computing Lab Sculpture Project

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×3
AC/DC Power Supply, External Plug In
AC/DC Power Supply, External Plug In
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Code

This is my overall code!

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 <ArduinoJson.h>

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

/**

Last updated: 01/14/2025

**/
int count = 0;
int oldN = 0;
int n = 0;
int ph;
int button = 5;
Servo myServo1;
Servo myServo2;
Servo myServo3;
// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>

// Include Particle Device OS APIs
#include "Particle.h"

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

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
//SerialLogHandler logHandler(LOG_LEVEL_INFO);
#if (PLATFORM_ID == 32)
#define PIXEL_PIN SPI1
#else
#define PIXEL_PIN D2
#endif

#define PIXEL_COUNT 6
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

String jsonText = "";
JsonDocument doc;
int triggerlight = 0;

void setup()
{
    sendInfo();
    strip.begin();
    Serial.begin(9600);
    pinMode(button, INPUT_PULLUP);
    // Particle.subscribe("hook-response/numShoot", retrieveValues, MY_DEVICES);
    Particle.subscribe("hook-response/numShoot", retrieveValues);
    
        strip.setPixelColor(0, 0, 0, 0);
        strip.setPixelColor(1, 0, 0, 0);
        strip.setPixelColor(2, 0, 0, 0);
        strip.setPixelColor(3, 0, 0, 0);
        strip.setPixelColor(4, 0, 0, 0);
        strip.setPixelColor(5, 0, 0, 0);
        strip.show();
        delay(200);
    
    myServo1.attach(1);
    myServo1.write(0);
    
    myServo2.attach(16);
    myServo2.write(0);
    
    myServo3.attach(15);
    myServo3.write(0);
}


void loop()
{
    int btnState = digitalRead(button);

        // n = 10;
        // oldN = 4;
        
        
        // if(n > oldN){
        
        //     actionBad();
        
        // }
        
        // if(n < oldN){
            
        //     actionGood();
            
        // }
        
        // if(n == oldN){
        //     //actionNuet();
        // }
        // delay(200);
        // Serial.print("Old N: ");
        // delay(100);
        // Serial.println(oldN);
        // delay(200);
        // Serial.print("Curr N: ");
        // delay(100);
        // Serial.println(n);
        // delay(200);
        // setN();

        test();
        delay(2000);

}

// ONLY use if the hook response has been split into multiples
// Has not been tested for a high number of hook responses.
// void handleEventResponse(const char *event, const char *data)
// {
//     jsonText += String(data);
//     Serial.println(jsonText);
    
//     retrieveValues();
// }


void retrieveValues(const char *event, const char *data)
{
    
    // The deserializeJSON method turns the JSON text object into a JsonDocument object
    // Note: You must retrieve the internal CONSTANT C representation of the string, c_str()
    //DeserializationError error = deserializeJson(doc, data);
    
    // ---- Error handling code from ArduinoJSON
    // if (error)
    // {
    //     Serial.print("deserializeJson() failed: ");
    //     Serial.println(error.c_str());
    //     return;
    // }
    // ---- end error handling
    
    
    // **** Let's retrieve data from a JSON object
    // cityName is a pointer to a constant sequence of characters


    // The deserializeJSON method turns the JSON text object into a JsonDocument object
    // Note: You must retrieve the internal CONSTANT C representation of the string, c_str()
    DeserializationError error = deserializeJson(doc, data);
    
    // ---- Error handling code from ArduinoJSON
    if (error)
    {
        Serial.print("deserializeJson() failed: ");
        Serial.println(error.c_str());
        return;
    }
    // ---- end error handling

    //JsonObject obj = doc[0];
    //const char* c = obj["count"];
    n = doc[0]["count"];

    if(count == 0){
        oldN = n;
        count++;
    }
    
    
    //String str = String(c);
    //n = str.toInt();
    
    //jsonText +=String(data);
    //n = atoi(jsonText);
    Serial.print("Number of shootings in the past month: ");
    Serial.println(n);
    //jsonText="";

    
    // **** Retrieving array of JSON objects
    // JsonArray weather = doc["weather"];
    
    // JsonObject weather_0 = weather[0];
    // const char* desc_0 = weather_0["description"];
     
    // JsonObject weather_1 = weather[1];
    // const char* desc_1 = weather_1["description"];
    
    // Serial.println(desc_0);
    // Serial.println(desc_1);
}

void sendInfo(){
    time_t startTime = Time.now() - 2629746;   // 4 days ago 345600
    time_t endTime = startTime + 2629746;       // 3 days ago
    
    // setup the time zone
    Time.zone(-6);  
    
    // Format the time in the same format as what the database uses
    String strEndTime = Time.format(endTime, TIME_FORMAT_ISO8601_FULL);
    
    // Remove some characters from the end. ISO8601 has two variations.
    // Particle doesn't use the same variation so we need to chop off the end of it
    strEndTime = strEndTime.substring(0, strEndTime.length()-6);
    
    // Do the same for min
    String strStartTime = Time.format(startTime, TIME_FORMAT_ISO8601_FULL);
    strStartTime = strStartTime.substring(0, strStartTime.length()-6);
    
    // Format the JSON string properly. It should look like:
    // {"minDate":"2023-03-13T14:11:11", "maxDate":"2023-03-14T14:11:11"}
    String data = "{\"minDate\":\"" + strStartTime + "\"";
    data += ", \"maxDate\":\"" + strEndTime + "\"}";
    
    // Print to confirm
    Serial.println(data);
    Serial.println(strStartTime);
    delay(100);
    
    // This line probably shouldn't be in setup
    // Testing here temporarily
    
    Particle.publish("numShoot", data);
    
}

void setN(){
    n = oldN;
}


void actionBad(){
    
    myServo1.write(170);
    delay(200);
    
    myServo2.write(0);
    delay(200);
    
    
    
    for(int i =0; i < 10; i++){
        strip.setPixelColor(0, 255, 0, 0);
        strip.setPixelColor(1, 255, 0, 0);
        strip.setPixelColor(2, 255, 0, 0);
        strip.setPixelColor(3, 0, 0, 0);
        strip.setPixelColor(4, 0, 0, 0);
        strip.setPixelColor(5, 0, 0, 0);
        strip.show();
        delay(200);
        
        strip.setPixelColor(0, 0, 0, 0);
        strip.setPixelColor(1, 0, 0, 0);
        strip.setPixelColor(2, 0, 0, 0);
        strip.setPixelColor(3, 0, 0, 0);
        strip.setPixelColor(4, 0, 0, 0);
        strip.setPixelColor(5, 0, 0, 0);
        strip.show();
        delay(200);
        
        strip.setPixelColor(0, 255, 0, 0);
        strip.setPixelColor(1, 255, 0, 0);
        strip.setPixelColor(2, 255, 0, 0);
        strip.setPixelColor(3, 0, 0, 0);
        strip.setPixelColor(4, 0, 0, 0);
        strip.setPixelColor(5, 0, 0, 0);
        strip.show();
        delay(200);
        

        
        strip.setPixelColor(0, 0, 0, 0);
        strip.setPixelColor(1, 0, 0, 0);
        strip.setPixelColor(2, 0, 0, 0);
        strip.setPixelColor(3, 0, 0, 255);
        strip.setPixelColor(4, 0, 0, 255);
        strip.setPixelColor(5, 0, 0, 255);
        strip.show();
        delay(200);
        
        strip.setPixelColor(0, 0, 0, 0);
        strip.setPixelColor(1, 0, 0, 0);
        strip.setPixelColor(2, 0, 0, 0);
        strip.setPixelColor(3, 0, 0, 0);
        strip.setPixelColor(4, 0, 0, 0);
        strip.setPixelColor(5, 0, 0, 0);
        strip.show();
        delay(200);
        
        strip.setPixelColor(0, 0, 0, 0);
        strip.setPixelColor(1, 0, 0, 0);
        strip.setPixelColor(2, 0, 0, 0);
        strip.setPixelColor(3, 0, 0, 255);
        strip.setPixelColor(4, 0, 0, 255);
        strip.setPixelColor(5, 0, 0, 255);
        strip.show();
        delay(200);

    } 
        strip.setPixelColor(0, 0, 0, 0);
        strip.setPixelColor(1, 0, 0, 0);
        strip.setPixelColor(2, 0, 0, 0);
        strip.setPixelColor(3, 0, 0, 0);
        strip.setPixelColor(4, 0, 0, 0);
        strip.setPixelColor(5, 0, 0, 0);
        strip.show();
        delay(200);
       
         myServo1.write(0);
    
    myServo2.write(170);

}


void actionGood(){
    
    myServo1.write(0);
    delay(1000);
    
    myServo2.write(170);
    delay(1000);
    
    strip.setPixelColor(0, 255, 255, 255);
        strip.setPixelColor(1, 255, 255, 255);
        strip.setPixelColor(2, 255, 255, 255);
        strip.setPixelColor(3, 255, 255, 255);
        strip.setPixelColor(4, 255, 255, 255);
        strip.setPixelColor(5, 255, 255, 255);
        strip.show();
        delay(200);    

         myServo1.write(170);
    
    myServo2.write(0);

}

void actionNeut(){
    
    myServo1.write(0);
    delay(1000);
    
    myServo2.write(170);
    delay(1000);
    
    strip.setPixelColor(0, 255, 255, 255);
        strip.setPixelColor(1, 255, 255, 255);
        strip.setPixelColor(2, 255, 255, 255);
        strip.setPixelColor(3, 255, 255, 255);
        strip.setPixelColor(4, 255, 255, 255);
        strip.setPixelColor(5, 255, 255, 255);
        strip.show();
        delay(200);    

         myServo1.write(170);
    
    myServo2.write(0);

}

void test(){
        delay(2000);
        myServo1.write(170);
        delay(2000);
        myServo1.write(0);
        delay(2000);
        
        myServo2.write(170);
        delay(2000);
        myServo2.write(0);
        delay(2000);
        
        myServo3.write(170);
        delay(2000);
        myServo3.write(0);
        delay(2000);
        
        
        strip.setPixelColor(0, 255, 0, 0);
        strip.setPixelColor(1, 255, 0, 0);
        strip.setPixelColor(2, 255, 0, 0);
        strip.setPixelColor(3, 255, 0, 0);
        strip.setPixelColor(4, 255, 0, 0);
        strip.setPixelColor(5, 255, 0, 0);
        strip.show();
        delay(2000);
        
        strip.setPixelColor(0, 0, 0, 0);
        strip.setPixelColor(1, 0, 0, 0);
        strip.setPixelColor(2, 0, 0, 0);
        strip.setPixelColor(3, 0, 0, 0);
        strip.setPixelColor(4, 0, 0, 0);
        strip.setPixelColor(5, 0, 0, 0);
        strip.show();
        delay(2000);
}

Credits

Gamya Michael
1 project • 0 followers

Comments