int servoPin = A3;
Servo servo;
bool servoPositionUpdated = false;
int servoPos = 0;
void setup() {
servo.attach(servoPin);
Particle.function("position", setPosition);
}
void loop() {
if (servoPositionUpdated == true){
servo.write(servoPos);
servoPositionUpdated = false;
}
}
int setPosition (String cmd) {
int input = cmd.toInt();
if (input > 180) {
return -1;
}
if (input < 0) {
return -1;
}
int angle = map(input, 15, 0, 0, 90); // map the input value to rotaton angle
servoPos = angle;
servoPositionUpdated = true;
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. .