Back to Parent

Particle Code
Servo rightServo;
Servo leftServo;
int right = D0;
int left = D1;
int servoRPos = 0;
int servoLPos = 0;

void setup() {
  // attaches the servo on the D0 pin to the servo object
  rightServo.attach(right);
  leftServo.attach(left);
  // Keep a cloud variable for the current position
  Particle.variable("servoPos", &servoRPos, INT);
  Particle.variable("servoPos", &servoLPos, INT);
  // Expose function to the cloud to be called by Maker IFTTT
  Particle.function("tweet", twitterMessage);
  servoControl(10, 170);
}


// Moves servo on input of angle from 0-180
int servoControl(int rightPos, int leftPos)
{
   servoRPos = constrain(rightPos, 0, 180);
   servoLPos = constrain(leftPos, 0, 180);
   // Set the servo
   rightServo.write(servoRPos);
   leftServo.write(servoLPos);
   return 1;
}


int twitterMessage(String command)
{
  int cmd = command.toInt();
  if (cmd == 1){
    servoControl(90, 90);
    delay(5000);
    servoControl(10, 170);
  }
  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