int servoPin = D2;
Servo myServo;
int servoPos = 0;
void setup() {
myServo.attach(servoPin);
Particle.function("Temperature", servoTemp);
Particle.function("Weather", servoWeather);
Particle.variable("ServoPos", servoPos);
}
void loop() {
}
int servoTemp(String command) {
int temp = command.toInt();
temp = constrain(temp, 0, 100); //make sure it's within range
servoPos = map(temp, 0, 100, 0, 180);
myServo.write(servoPos);
return 1;
}
int servoWeather(String command) {
int weather = command.toInt();
if (weather == 1){
servoPos = 0;
} if (weather == 2){
servoPos = 45;
} if (weather == 3){
servoPos = 135;
} if (weather == 4){
servoPos = 180;
}
myServo.write(servoPos);
return 1;
}
Click to Expand