SkillDev_Output

Made by Ziru Wei

prototype a ambient object that can react to real time info

Created: November 22nd, 2024

0

[Intention]

When we neglect our garden for a long time, we often find it overgrown with weeds. Similarly, when we've been working at our computers for too long, our energy is no longer sufficient for high-density tasks, yet we still sit there idly, fatigued but unable to move. 

Perhaps, during such moments, your computer might even start "growing grass" too. What you really need is a little reminder—something cute, like a sprout—to encourage you to step outside onto the lawn and breathe in some fresh air!🌳🌳🌳

0

[try to work with motor in Particle] :

0
int servoPin = D1;
int servoPosition = 0;
Servo servo;

bool shouldWobble = false;
bool shouldCountdown = false;

void setup() {
    servo.attach(servoPin);
    servo.write(0);
    delay(500);
    servo.write(180);
    delay(500);
    servo.write(90);
    delay(500);

    Particle.function("wobble", handleWobble);
    Particle.function("counter", handleCounterStart);
}

int handleWobble(String cmd) {
    shouldWobble = true;
    return 1;
}

int handleCounterStart(String cmd) {
    shouldCountdown = true;
    return 1;
}

void loop() {
    if (shouldWobble) {
        for (int i = 0; i < 10; i++) {
            servo.write(70);
            delay(100);
            servo.write(110);
            delay(100);
        }
        shouldWobble = false;
    }

    if (shouldCountdown) {
        for (int i = 180; i >= 0; i -= 5) {
            servo.write(i);
            delay(250);
        }
        shouldCountdown = false;
    }

    delay(1000);
}
Click to Expand
0

[Outcome]

0
#include "Particle.h"
#include <Servo.h>

int servoPin = D1;
int servoPosition = 0;
Servo servo;

bool moveTo90 = false;
bool resetTo0 = false;

void setup() {
    servo.attach(servoPin);
    servo.write(0);
    delay(500);
    Particle.function("controlMotor", handleMotorCommand);
}

int handleMotorCommand(String command) {
    if (command == "1") {
        moveTo90 = true;
        resetTo0 = false;
        return 1;
    } else if (command == "0") {
        resetTo0 = true;
        moveTo90 = false;
        return 1;
    }
    return -1;
}

void loop() {
    if (moveTo90) {
        servo.write(90);
        delay(500);
        moveTo90 = false;
    }

    if (resetTo0) {
        servo.write(0);
        delay(500);
        resetTo0 = false;
    }

    delay(100);
}
Click to Expand
0

Workflow:

- The Particle device receives a command ("1" or "0") from the cloud.

- Updates the flags based on the input.

- In the loop(), the servo moves to 90 degrees if moveTo90 is true or resets to 0 degrees if resetTo0 is true.

- Each movement is followed by a 500ms delay to ensure the motor has time to reach the target position.

x
Share this Project


Focused on
About

prototype a ambient object that can react to real time info