nt servoPin = A4;
int servoPosition = 0;
Servo myServo;
void setup() {
// attaches the servo on the A3 pin to the servo object
myServo.attach( A4 );
//Register our Particle to control the servo
Particle.function("servo", servoControl);
// Keep a cloud variable for the current position
Particle.variable( "servoPosition" , &servoPosition , INT );
}
void loop() {
}
int servoControl(String command)
{
// Convert
int newPosition = command.toInt();
// Make sure it is in the right range And set the position
servoPosition = constrain( newPosition, 0 , 180);
// Set the servo
myServo.write( servoPosition );
// done
return 1;
}
Click to Expand