Gunnar Nicewick
Published

Light of the Dancer

A project featuring a dancer that spins if there is a play happening in downtown Chicago.

BeginnerFull instructions provided-120 minutes11
Light of the Dancer

Things used in this project

Hardware components

Stepper Motor
Digilent Stepper Motor
×1
Photon 2
Particle Photon 2
×1
COB LED Holder, 50mm DIA
COB LED Holder, 50mm DIA
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Code

light_of_the_dancer

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Stepper.h>
// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);
JsonDocument doc;
int traffic = 30;
bool done = true;
const int stepsPerRevolution = 2048; 

// Any digital pins should work. Change as necessary.
#define IN1 2
#define IN2 3
#define IN3 4
#define IN4 5

// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
Stepper myStepper(stepsPerRevolution, IN1, IN3 , IN2, IN4);
void setup()
{
    Serial.begin(9600);
    pinMode(8, OUTPUT);
    digitalWrite(8, HIGH);
    Serial.println("Particle connected to cloud!");
    myStepper.setSpeed(0);
  
    while(Particle.disconnected()) ;
  
    // Adjustable range of 28BYJ-48 stepper is 0~17 revolutions per minute
    // Optimal is 10-17 rpm

    Particle.subscribe("hook-response/dTraffic/", extractInfo);
}

void loop()
{
    if(done){
        String data = String(10);
        Particle.publish("dTraffic", data, PRIVATE);
        done = false;
    }
    if(Time.minute() == 0){
        String data = String(10);
        Particle.publish("dTraffic", data, PRIVATE);
        done = false;
    }
    float base = (traffic-15.0);
    double expo = (cbrt(base));
    Serial.println(traffic);
    Serial.println(base);
    Serial.println(expo);
    myStepper.setSpeed((int)((-3*expo)+9));
    Serial.println((int)((-3*expo)+9));
    myStepper.step(stepsPerRevolution);
}

void extractInfo(const char *event, const char *data)
{
    Serial.println("Handler is starting...");
    deserializeJson(doc, data);
    JsonObject root_0 = doc[0];
    traffic = root_0["_traffic"];
    myStepper.setSpeed(traffic);
    Serial.println(traffic);
}

Credits

Gunnar Nicewick
1 project • 0 followers

Comments