//skill dev 4
Servo myServo;
int servoPin = A3;
int servoPos = 0;
int Pos0 = 90;
int Pos1 = 60;
int Pos2 = 120;
int times = 3;
int interval = 200;
void setup() {
// attaches the servo on the A3 pin to the servo object
myServo.attach( A3 );
//Register our Particle to control the servo
Particle.function("phone", phone);
Particle.function("p1", p1);
Particle.function("p2", p2);
// Keep a cloud variable for the current position
Particle.variable( "servoPos" , &servoPos , INT );
}
void phoneRings(int times){
for(int i = 0; i<times;i++){
servoPos = Pos1;
myServo.write( servoPos );
delay(interval);
servoPos = Pos2;
myServo.write( servoPos );
delay(interval);
}
servoPos = Pos0;
myServo.write( servoPos );
}
void loop() {
}
int phone(String command)
{
times = command.toInt();
constrain(times,1,10);
phoneRings(times);
// done
return 1;
}
int p1(String command)
{
Pos1 = command.toInt();
constrain(Pos1,20,70);
phoneRings(times);
// done
return 1;
}
int p2(String command)
{
Pos2 = command.toInt();
constrain(Pos2,100,160);
phoneRings(times);
// 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. .