Back to Parent

Servo myServo;
int servoPos = 0;

void setup() {

    myServo.attach( A3 );
    Particle.function("Current_Temperature", servoControl);
    Particle.variable(  "servoPos" , &servoPos , INT );
}

void loop() {

}

int servoControl(String command)
{
    // Convert
    int newPos = command.toInt();
    // Make sure it is in the right range
    // And set the position
    int veryCold= 18;
    int cold= 55;
    int cool= 91;
    int warm= 127;
    int hot= 163;
    if( newPos<=0){
     servoPos = constrain( veryCold, 0 , 180);
    }else if(newPos> 0 & newPos <=8){
     servoPos = constrain( cold, 0 , 180);
    }else if(newPos> 8 & newPos <=18){
     servoPos = constrain( cool, 0 , 180);
    }else if(newPos> 18 & newPos <=29){
     servoPos = constrain( warm, 0 , 180);
    }else if(newPos> 29){
     servoPos = constrain( hot, 0 , 180);
    }
    
   // Set the servo
   myServo.write( servoPos );

    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