Back to Parent

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

void setup() {
    myServo.attach( A3 );
    
    Particle.function("servoStart", servoStart);
    Particle.function("servoEnd", servoEnd);
    Particle.variable(  "servoPos" , &servoPos , INT );
}


void loop() {
    
}


int servoStart(String command){
    for (servoPos = 0; servoPos <= 180; servoPos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
        myServo.write(servoPos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
        }
 

   // done
   return 1;
}

int servoEnd(String command) {
    for (servoPos = 180; servoPos >= 0; servoPos -= 1) { // goes from 180 degrees to 0 degrees
        myServo.write(servoPos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
    }
    
    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