Back to Parent

int servoPin = A3;
Servo myServo;
int servoPos = 0;

void setup() {
    myServo.attach(A3);
    myServo.write(90);
    
    //Register our Particle to control the servo
    Particle.function("servo", servoControl);
    Particle.function("trashbin", binControl);
   
   // Keep a cloud variable for the current position
    Particle.variable(  "servoPos" , &servoPos , INT );
}

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;
}

int binControl(String args) {
    unsigned long now = millis();
    unsigned long initialized = millis();  
    
    while ((now - initialized) < 3600000) {
        myServo.write(90);
        delay(1000);
        myServo.write(5);
        delay(1500);
        now = millis();
    }
    
    return 1;
}

void loop() {
    
}
Click to Expand

Content Rating

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

0