Back to Parent

int servoPin = A5;
Servo myServo;
int servoPos = 0;
int degree = 0;
void setup() {
  // attaches the servo on the A5 pin to the servo object
  myServo.attach( A5 );
  //Register our Particle to control the servo
  Particle.function("servo", servoControl);
  // Keep a cloud variable for the current position
  Particle.variable(  "servoPos" , &servoPos , INT );
  //We "Subscribe" to our IFTTT event called Button so that we get events for it
    Particle.subscribe("Tweet", myHandler);
}
void loop() {
  void myHandler();
  // for (int i=0; i <= 360; i++){
  //   myServo.write(degree);
  //   delay (1000);
  //   degree = degree + 60;
  //  }
  //  degree = 0;
}
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 , 180);
   // Set the servo
   myServo.write( servoPos );
   // done
   return 1;
}
//The function that handles the event from IFTTT
void myHandler(const char *event, const char *data){
  //Trigger motor to turn 60 degrees
  degree = degree + 30;
  myServo.write(degree);
  delay (1000);
}
Click to Expand

Content Rating

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

0