Back to Parent

// define servo
Servo servo0;
Servo servo1;

int servoPos = 0;


void setup() {
    // attaches the servo on the A2-5 pins to the servo objects
    servo0.attach( A2 );
    servo1.attach( A3 );
  
    //Register our Particle to control the servo
    Particle.function("servo", servoControl);
    
    // Keep a cloud variable for the current position
    Particle.variable(  "servoPos" , &servoPos , INT );
}

void loop() {
}

int servoControl(String command)
{
    // Convert
   int newPos = command.toInt();
   // Make sure it is in the right range
   // And set the position
   servoPos = constrain( newPos, 0 , 270);

   // Set the servo
   servo0.write( servoPos );
   servo1.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!

0