Hi,
Without too much thinking involved, I just ordered two of these from eBay
I’m wondering whether I can run these motors directly from pins on the Photon without any other hardware (other than a jumper cable) since they come with a driver board included? Also, can I run them using the ‘servo’ control library? Below is the code I’d like to use, if possible. What do we think?
Thanks!
Tim
Code Starts Here
// ** NOTES
// ** posStatus1 -> Reed switch for openServo -> HIGH=DISENGAGED, LOW=ENGAGED
// ** posStatus2 -> Reed switch for twistServo -> HIGH=DISENGAGED, LOW=ENGAGED
// ** openServo -> Operates string that moves blinds apart -> HIGH=CLOSED
// ** twistServo -> Operates beaded cord that turns blinds -> HIGH=FLUSH
// **
// **
int servoPin1 = D0; // ToggleOpen servo
Servo openServo;
int servoPin2 = D1; // ToggleTwist servo
Servo twistServo;
int posDetector1 = D2; // ToggleOpen switch input
int posDetector2 = D3; // ToggleTwist switch input
int servoPos = 0; // Reset servo position
int posStatus1 = 0; // Position status variable ToggleOpen
int posStatus2 = 0; // Position status variable ToggleTwist
void setup() {
openServo.attach( servoPin1 ); // Attach Toggle servo to D0
Particle.function("toggleBlinds", toggleBlinds);
twistServo.attach( servoPin2 ); // Attach Twist servo to D1
Particle.function("twistBlinds", twistBlinds);
pinMode(posDetector1, INPUT_PULLDOWN); // Check status of ToggleOpen switch
pinMode(posDetector2, INPUT_PULLDOWN); // Check status of ToggleTwist switch
Particle.variable("posStatus1", &posStatus1, INT); // Declare status variable to check ToggleOpen position status
Particle.variable("posStatus2", &posStatus2, INT); // Declare status variable to check ToggleTwist position status
}
// ToggleOpen blinds open/closed
int toggleBlinds(String command) {
posStatus1 = digitalRead(posDetector1); // Status of ToggleOpen switch
posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
if (posStatus1 == LOW, posStatus2 == LOW) // If OPEN and NOT FLUSH to window then this closes and aligns them
openServo.write( -360 ), // Pulls curtains together
delay(500), // Half second pause
twistServo.write( 180 ); // Twists to close flush to window
else if (posStatus1 == LOW, posStatus2 == HIGH) // If OPEN and FLUSH to window then this closes them
openServo.write( -360 ); // Pulls curtains together
else if (posStatus1 == HIGH, posStatus2 == LOW) // If CLOSED and NOT FLUSH to the window, this opens them
openServo.write( 360 ); // Pulls curtains apart
else if (posStatus1 == HIGH, posStatus2 == HIGH) // If CLOSED and FLUSH to the window, this opens and aligns them
twistServo.write( -180 ), // Twists so perpendicular to window
delay(500), // Half second pause
openServo.write( 360 ); // Pulls curtains apart
else return (-1);
}
// ToggleTwist blinds open/closed
int twistBlinds(String command) {
posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
if (posStatus2 == LOW) // If FLUSH TO WINDOW
twistServo.write( 180 );
else
twistServo.write( -180 );
}
// Ignore
void loop() {
}