hey guys... here's what i'm attempting: servo rotates until switch is tripped (let's say it's flipped to position 2)... easy peasy... the servo will then sit idle until activated with a separate button... and once the servo is activated again (the switch has not been touched and remains in position 2), i want to run until the switch is tripped again, but now in the opposite direction to position 1... so basically the switch has 2 "off" triggers, 1 in each side..
should i be using a 3-way toggle switch?.. or do i use a slider in this case?.. or is there a better method?.. open to all suggestions and opinions
The servo turns one direction and presses the switch, the software remembers that it has been pressed (and allows no further action on that side) until it sees a press on the other side.
Benefit is that you are not overcoming a large mechanical force to press the switch like a toggle switch would have.
thanks @CrossRoads... your suggestion makes sense...
i think i need to elaborate a bit on my goal... i have a button that'll start the servo which then runs until a hardware interrupt (for example a slide switch)... this will stop the rotation... now when the button is pressed again, it turns the servo in the opposite direction... until the slide switch is flipped to the other side... what i can't quite grasp is will the slide switch which interrupted the servo, now keep it from turning since it's still stuck in that "interrupt" position?.. or will the software not care about that?..
No could use same one. Plenty of clock cycles to disable when its tripped, then re-attach after servo starts moving the other direction.
Could SPDT - an on-on switch. Center to gnd, outers to the interrupt pin. Low interrupt with internal pullup enabled.
can some of you guys take a look at my ugly code and give me some pointers how to clean it up an make it more efficient (if necessary)... the idea is to have a servo act almost like a garage door - when a button is pressed, rotate in one direction until a hardware interrupt (bumper/lever/switch/whatever); do nothing until button is pressed again then rotate in the opposite direction until hardware interrupt... so far i think i got it to do everything except i don't know how to implement that second interrupt... do i just put another bumper on pin 3?.. is there a more efficient way to do it with a single switch, spdt or dpdt?..
//zoomkat servo button toggle test 4-28-2012
#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int button2 = 2; //button pin, connect to ground to move servo
Servo myServo;
boolean drawIsOpen = false;
// Interrupt Service Routine (ISR)
void pinChange ()
{
myServo.writeMicroseconds(1500); // Stop
drawIsOpen = !drawIsOpen; // flip direction
Serial.print(drawIsOpen);
} // end of pinChange
void setup()
{
pinMode(button1, INPUT); //arduino monitor pin state
pinMode(button2, INPUT); //arduino monitor pin state
myServo.attach(9); //pin for servo control signal
digitalWrite(button1, HIGH); //enable pullups to make pin high
digitalWrite(button2, HIGH); //enable pullups to make pin high
attachInterrupt (0, pinChange, FALLING); // attach interrupt handler
Serial.begin(9600); // open the serial port at 9600 bps:
}
void loop()
{
if (digitalRead (button1) == LOW)
{
if(drawIsOpen)
{
myServo.writeMicroseconds(1700); // Counter clockwise to close door
// drawIsOpen = false;
Serial.print(drawIsOpen);
// delay(160000); // Wait X seconds
}
else
{
myServo.writeMicroseconds(1300); // Clockwise
// drawIsOpen = true;
Serial.print(drawIsOpen);
}
}
delay(200); //delay for debounce
}