Back to Parent

int servoPin = A3;
Servo myServo;
int servoSpeed = 90;


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("Time spent on your phone (Hour)", servoControl);

  // Keep a cloud variable for the current position
  Particle.variable(  "servoSpeed" , &servoSpeed , INT );  
}

int servoControl(String command)
{
    // Convert
   int newSpeed = command.toInt();
   // Make sure it is in the right range
   // And set the position
   newSpeed   = map(newSpeed,0,8,90,180);
   servoSpeed = constrain(newSpeed, 90 , 180);

   // Set the servo
   myServo.write( servoSpeed );

   // 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