I wrote a code to control by blinds tilt. It works: it makes correct amount of turns and then stops. The only problem that once it stops it continues to pulsate until you physically disconnect the circuit.
I am trying to add a function to detach servo, but nothing works so far
Here is the code:
//Create servo object to control a servo
Servo myServo;
int posCurrent;
void setup()
{
//Attaches the servo on pin D0 to the servo object
myServo.attach(D0);
posCurrent = 0;
//Register our Particle to control the servo
Particle.function("openBlinds", openBlinds);
Particle.function("closeBlinds", closeBlinds);
}
void loop()
{
}
int openBlinds(String command)
{
int newPos = command.toInt();
// Make sure it is in the right range
// And set the position
posCurrent = constrain( newPos, 0 , 90);
// Set the servo
myServo.write( posCurrent );
// done
return 1;
}
int closeBlinds(String command)
{
int newPos = command.toInt();
// Make sure it is in the right range
// And set the position
posCurrent = constrain( newPos, 90 , 0);
// Set the servo
myServo.write( posCurrent );
// done
return 1;
}