Back to Parent

int servoPin = A2;
int servoPosition = 0;
Servo servo;

void setup()
{
    Serial.begin( 9600 );
    Particle.function( "pos", setPosition );
    servo.attach( servoPin );
}

void loop()
{
    delay(100);
}

int setPosition( String timeBeforeArrivalStr ){
    int timeBeforeArrival = timeBeforeArrivalStr.toInt();

    // servo.write( timeBeforeArrival ); 
    // return timeBeforeArrival;

    
    if (timeBeforeArrival >= 10) {
        servo.write( 175 );
    }
    
    if (timeBeforeArrival < 10 && timeBeforeArrival > 5) {
        servoPosition =  map(timeBeforeArrival, 10, 5, 30, 80); 
        servo.write( servoPosition );        
    }
    
    
    if (timeBeforeArrival <= 5 && timeBeforeArrival >= 3) {
        servo.write( 80 ); 
    }
    
    if (timeBeforeArrival < 3) {
        servo.write( 90 );
    }
    
    delay(1000);
    
    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