Back to Parent

nt servoPin = A4;
int servoPosition = 0;
Servo servo;
bool updatePosition = true;
void setup()
{
  Serial.begin( 9600 );
  Particle.function( "pos", setPosition );
  servo.attach( servoPin );
}
void loop()
{
    
  if( updatePosition == true ){
    updatePosition = false;
    }
  }
    


int setPosition( String command ){
  Serial.println( "setSpeed: " + command );
  int value = command.toInt();
  if( value < 0 ) return -1;
  if( value > 180 ) return -1;
  servoPosition = constrain( value, 0, 180 );
  updatePosition = true;
  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