// Define the varibles and call Servo library with an instance called "myServo"
int servoPin = A3;
Servo myServo;
int servoPos = 0;
void setup() {
// Attach the Servo to pin A3 as a reference
myServo.attach (A3);
// Register variable servoControl to particle cloud (input named 'servo') 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 Particl cloud to an integer we can use
int newPos = command.toInt();
// constrain the entered position so it is between 0 - 180
servoPos = constrain( newPos, 0, 180);
// set the Servo
myServo.write( servoPos);
// finished
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. .