Back to Parent

//Skills Dev 4

//Set Servo pin
int servoPin = A3;
//Setup my servo command
Servo myServo;

//Initialize Servo position
int servoPos = 0;

//Jitter loop length
int jitterLength = 5;

void setup() {
    
    // attaches the servo on the A3 pin to the servo object
    myServo.attach( A3 );
    
    //Register our Particle to control the servo
    Particle.function("Best Friend Alert", servoControl);

    // Keep a cloud variable for the current position
    Particle.variable(  "servoPos" , &servoPos , INT );
    
    //Test that servo is initiated and move through motions
    myServo.write(60);
    delay(200);
    myServo.write(170);
    delay(200);
}

void servoJitter() {
    //Raise Flag
    for (int i = 0; i < 3; i++ ) {
        
        myServo.write(170);
        delay(200);
        //Wave Flag
        for (int i = 0; i < jitterLength; i++) {
            myServo.write( 80 );
            delay(100);
            myServo.write( 100 );
            delay(100);   
        } 
        //Lower Flag
        myServo.write(170);
        delay(1000);
    }
    
}


int servoControl(String command) {
    //Flag process
    servoJitter();
    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