#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
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .