Leon Scurtu
Published

Moving Sculpture collaboration

This moving art piece is meant to represent the continuous hardship in the US by reacting to the live national debt.

IntermediateShowcase (no instructions)8 hours41
Moving Sculpture collaboration

Things used in this project

Hardware components

SG90 Micro-servo motor
SG90 Micro-servo motor
×2
Photon 2
Particle Photon 2
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Perma-Proto Breadboard Half Size
Perma-Proto Breadboard Half Size
×1
Grove - WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m
Seeed Studio Grove - WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

12V, 40W Soldering Pencil Set for RT3 Soldering Tips with Safety Rest contains Stop and Go Function
12V, 40W Soldering Pencil Set for RT3 Soldering Tips with Safety Rest contains Stop and Go Function

Story

Read more

Schematics

top

top of the board

bottom

bottom of the board

whole

Code

code

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

#include <ArduinoJson.h>

#include <iostream>
#include <string>
#include <stdexcept>

using namespace std;

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#if (PLATFORM_ID == 32)
#define PIXEL_PIN SPI1
#else //
#define PIXEL_PIN D2
#endif

#define PIXEL_COUNT 3
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);
Servo myServo; 
JsonDocument doc;
String jsonText = "";
int button = 6;
bool requestSent = false; 
unsigned long lastRequestTime = 0;
const unsigned long debounceDelay = 2000; 

void setup() {
    Serial.begin(9600);
    pinMode(button, INPUT_PULLUP);
    strip.begin();
    strip.show();
    myServo.attach(1); // Attach servo to pin 4
    Particle.subscribe("hook-response/ssdsds", handleEventResponse, MY_DEVICES);
}

void loop() {
    int btnState = digitalRead(button);
    Serial.println("Button: " + String(btnState));

    if (btnState == LOW && !requestSent) {
        Particle.publish("ssdsds", PRIVATE);  // Consider changing event name
        Serial.println("Just published!");
        requestSent = true;
        lastRequestTime = millis();
    }

    if (requestSent && (millis() - lastRequestTime > debounceDelay)) {
        requestSent = false;
    }

    delay(500);  // Loops every 500ms
    Serial.println("Loop ends!");
}

void handleEventResponse(const char *event, const char *data) {
    long debt = stod(data);
    Serial.println(debt);
     if (debt >366666.53) {
            myServo.write(150);
            colorAll(strip.Color(250,200, 0), 900); 
            delay(700);
            strip.clear();
            strip.show();
            delay(700);
            colorAll(strip.Color(250,200, 0), 900); 
            delay(700);
            strip.clear();
            strip.show();
            delay(700);
            colorAll(strip.Color(250,200, 0), 900); 
            strip.clear();
            strip.show();
            delay(700);
            colorAll(strip.Color(250,200, 0), 900); 
            strip.clear();
            strip.show();
          myServo.write(90);// Turn off the LEDs after 5 seconds
    }


}

void colorAll(uint32_t c, uint16_t wait) {
    for (int i = 0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c);
    }
    strip.show();
    delay(wait);  // Delay for the specified wait time
}

Credits

Leon Scurtu
2 projects • 0 followers

Comments