int servoPin = A3;
Servo myServo;
bool servoPositionUpdated = false;
int servoPosition = 0;
void setup() {
myServo.attach(servoPin);
Particle.function("pos", setPosition);
}
void loop() {
if (servoPositionUpdated == true){
myServo.write(servoPosition);
servoPositionUpdated = false;
}
}
int setPosition(String command){
int value = command.toInt();
if (value>180) {
return -1;
}
if (value<0){
return -1;
}
servoPosition = value;
servoPositionUpdated = true;
}
Click to Expand