Back to Parent

int servoPin = A3;
Servo servo;
bool servoPositionUpdated = false;
int servoPosition = 0;

void setup() {
// attaches the servo on the A3 pin to the servo object
  servo.attach( servoPin );

   //Register our Particle to control the servo
   Particle.function("pos", setPosition);

  // Keep a cloud variable for the current position
}

void loop() {

    if (servoPositionUpdated == true){
        servo.write(servoPosition);
        servoPositionUpdated = false;
    }
}

int setPosition(String command)
{
    // Convert
   int value = command.toInt();
   if( value >180 ) {
       return -1;
    }
   if( value < 0 ) {
       return -1;
    }

    servoPosition = value;
    servoPositionUpdated = true;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0