#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
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. .