Joel D
Published

Computational Sculpting Project

Sculpting project mixed with technical ideas!

BeginnerFull instructions provided6
Computational Sculpting Project

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Stepper Motor
Digilent Stepper Motor
×1
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Stripper, Automatic
Wire Stripper, Automatic
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

Code

C/C++
#include <Stepper.h>
#include <neopixel.h>
#include <ArduinoJson.h>
#include <AccelStepper.h>
#include "Particle.h"

SYSTEM_MODE(AUTOMATIC);

#if (PLATFORM_ID == 32)
#define PIXEL_PIN SPI1
#else
#define PIXEL_PIN D2
#endif

#define PIXEL_COUNT 30
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

#define HALFSTEP 8
AccelStepper motor(HALFSTEP, D0, D4, D1, A0);

float uvLevel = 0;
JsonDocument doc;

int red = 0;
int green = 255;
int blue = 0;
int mils = 500;
bool didRun = false;
bool frozen = false;
int endpoint = 4096;

void setup() {
    Serial.begin(9600);
    while(Particle.disconnected()) ;
    Serial.println("Particle connected to cloud!");

    strip.begin();
    strip.setBrightness(50);
    strip.show();

    motor.setMaxSpeed(1000.0);
    motor.setSpeed(1000);

    Particle.subscribe("hook-response/get_uv/0", extractUV);
    Particle.publish("get_uv");
}

void loop() {
    motor.runSpeed();
    if(!frozen) {
        changeColor(red, green, blue, mils);
    }
     static unsigned long lastCheck = 0;
    if(millis() - lastCheck >= 1800000) {
        lastCheck = millis();
        Particle.publish("get_uv");
    }
}

void extractUV(const char *event, const char *data) {
    String response = String(data);
    int start = response.indexOf("[") + 1;
    int end = response.indexOf("]");
    String uvText = response.substring(start, end);
    uvLevel = uvText.toFloat();
    Serial.println("UV Level: ");
    Serial.println(uvLevel);
    if(uvLevel > 0) {
        determineChange(uvLevel);
    }
}

void determineChange(float current) {
    Serial.println(current);
    if(current < 3) {
        red = 0;   green = 255; blue = 0;   mils = 600;
    } else if(current < 6) {
        red = 148; green = 0;   blue = 211; mils = 350;
    } else if(current < 8) {
        red = 255; green = 100; blue = 0;   mils = 200;
    } else {
        red = 255; green = 0;   blue = 0;   mils = 100;
    }
}

void changeColor(int r, int g, int b, int del) {
    static float brightness = 0.0;
    static float step = 0.005;
    static unsigned long lastUpdate = 0;

    int interval = max(del / 100, 5); 
    if(millis() - lastUpdate >= (unsigned long)interval) {
        lastUpdate = millis();

        brightness += step;
        if(brightness >= 1.0) { brightness = 1.0; step = -step; }
        if(brightness <= 0.0) { brightness = 0.0; step = -step; }

        int rr = (int)(r * brightness);
        int gg = (int)(g * brightness);
        int bb = (int)(b * brightness);

        for(int i = 0; i < PIXEL_COUNT; i++) {
            strip.setPixelColor(i, strip.Color(rr, gg, bb));
        }
        strip.show();
    }
}

Credits

Joel D
2 projects • 0 followers
Thanks to Lizbeth Corona.

Comments