Ye Olde Status Clokke
Made by Leslie Liu
Made by Leslie Liu
Understanding motors and servos.
Created: November 26th, 2024
Inspired by the Weasley family clock in the Harry Potter series; Paper Signals (Isaac Blankensmith, Glenn Cochon, Matthew Carey, Smooth Technology, and Kelly Ann Lum) — as well as certain artfully constructed metallic and magnetic status boards in the basements of Margaret Morrison Carnegie Hall — I wanted to make a simple deskside device that I could use daily, integrating a servo's movement and Particle cloud functions.
Originally I had wanted to play with the tradition of European medieval manuscript marginalia and the figure of the manicule —but then realized setting up a rig would likely be overpowering/overengineered. While the wireup was generally free of troubles, I initially ran into some issues programming, as I had forgotten — briefly — that the servo.write() function takes in resultant angles, rather than differences in angular rotation. Code is as follows.
#include "Particle.h"
int servoPin = D15;
int servoPos = 0;
SYSTEM_MODE(AUTOMATIC);
Servo serv;
SerialLogHandler logHandler(LOG_LEVEL_INFO);
bool shouldWobble = false;
bool shouldCountdown = false;
void setup() {
Serial.begin(9600);
serv.attach(servoPin);
Particle.function("setStatus",handleSetStatus);
Particle.function("tweak",handleTweak);
}
// this debugging function lets me fine tune servo position.
int handleTweak(String cmd) {
if (cmd=="a") {
serv.write(10);
delay(1000);
serv.write(-10);
delay(1000);
}
delay(1000);
int deg = cmd.toInt();
serv.write(deg);
return 1;
}
int handleSetStatus(String cmd) {
int tgtAngle = 0;
int n = 120; // 120 is true north
if (cmd == "working") {
tgtAngle = 150;
} else if (cmd == "away") { // alas this does not work due to the range of motion of the micro servo
tgtAngle = 180;
} else if (cmd == "out") { // alas this does not work either
tgtAngle = -180;
} else if (cmd == "meeting") {
tgtAngle = 0;
} else if (cmd == "available") {
tgtAngle = 70;
} else {
tgtAngle = 120;
}
serv.write(tgtAngle);
int fakeDelay = 1000*60; // 60 second delay
delay(fakeDelay);
serv.write(n);
return 1;
}
void loop() {
}
Click to Expand
Ye Olde Status Clokke is working! But due to the microservo’s 180˚ range of motion, I can never set it to “away” or “out” — using a DC motor may have avoided this altogether... but folks don't need to know :') Another way I post-rationalized this was the fact that if I were physically absent from/at my desk, that's enough of a sign that I’m out/away... By using the fake delay to simulate a period of time passing, I was able to bring this device to semi-imaginable realms. Ideally, personally the availability updates would be triggered by a physical switch, rather than typing on my computer into the Particle cloud — since the former feels more like a definitive shift into a new state/activity.
Understanding motors and servos.