// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_PWMServoDriver.h>
int servoPin = A3;
Servo myServo;
int servoPos = 0;
void setup() {
myServo.attach( A3 );
Particle.function("servo", servoControl);
// Keep a cloud variable for the current position
Particle.variable( "servoPos" , &servoPos , INT );
}
void loop() {
}
int servoControl(String command)
{
// Convert
int newPos = command.toInt();
// Make sure it is in the right range
// And set the position
servoPos = constrain( newPos, 0 , 180);
// Set the servo
myServo.write( servoPos );
// done
return 1;
}
Click to Expand