//Using a Servo
int servoPin = A3;
Servo myServo;
int servoPos = 0;
void setup() {
// Attach the servo on the A3 pin to the servo object
myServo.attach (A3);
// Register to particle cloud to control Servo from cloud
Particle.function ("servo", servoControl);
// Keep a cloud variable for the current position
Particle.variable ("servoPos", &servoPos, INT);
}
void loop() {
}
int servoControl(String command)
{
// convert string command from Particle cloud to an integer
int newPos = command.toInt();
// make sure it is in the right range 0-180
// set the position
servoPos = constrain( newPos, 0, 180);
// set the Servo
myServo.write( servoPos);
// done
return 1;
}
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. .