I have been doing a bunch of testing to try to figure out why the program gets stuck if the
servo is not allowed to get to its programmed position.
I have 6 buttons controlling one servo and each one does something a little different.
2 of the Button that are mechanical button
and 4 Buttons (A<B<C<D)of them are digital button from a rf transmiter.
Button B has a timer set to it so that the servo will move to position and wait till the timer times out.
once the timer times out the servo moves back to center position toggle= 0 servo .Write (65)
No matter if the servo is stuck or not once timed out will go back to Center location Servo.write(65). If the servo is not stuck and does get to its commanded location I can push
button D and by pass the timer and move the servo to position 65. But if the servo does not
get to comaned location D button will not bypass the counter and move the servo back to
position (65).
I put a serial print in the If (toggle == 0) myservo.write (65) statement and the "not"
continues to print untill the timer times out even if the other buttons are pushed
Both B and D buttons are digital input buttons.
The mechanical buttons will interupt the timer but the Digital buttons will not if the servo
is not allowed to get to position.
My thought is the digital inputs are not true inputs there for do not work the same as the
Mechanical inputs. That is also why I have them setting a variables (toggle) to set a position on the servo. This helped to make the program work in the begining
Any thoughts on how to get around the Servo out of position to be interuped with the digital inputs.
Seems the myservo.write does some sort of loop that keeps the program form continuing when it is not in position.
Ron
/* Garage door opener
modified 2 march 2018
by Ron Needham
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int toggle = 0;
int lock = 0;
int latch = 0 ;
int Buttons =0; //Buttons in control
unsigned long Reset = 5000 ; // 20000= 20 sec timmer for rest to off
unsigned long lowreset = 200 ;
unsigned long timmer = 0;
unsigned long CurrentMillis = millis();
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
// initialize the pushbutton pin as an input:
}
void loop()
{
CurrentMillis = millis();
if ((millis() - Reset )> timmer && lock == 1 ) // and or statment
{ toggle = 3;} // Sets the servo back to center after time out Door up
if ((millis() - Reset )> timmer && latch == 1)
{ toggle = 3; } // toogle 3 sets swithc back to off on the door
if (digitalRead (2)== HIGH && lock == 1){ // Door OPEN
Serial.println("ButtonA");
Reset=12000;
toggle = 1;
timmer = millis();
}
if (digitalRead (3)== HIGH){ // Door Close
Serial.println("ButtonB");
toggle = 0;
lock = 0 ;
timmer = millis();
latch = 1;
Reset = 10000;
}
if (digitalRead (4)== HIGH){
Serial.println("Button D"); //
toggle = 3;
lock = 0;
Reset = 0;
timmer = millis();
}
if (digitalRead (5)== HIGH){
Serial.println("Button C");
lock = 1;
}
if (toggle ==1 )
{ myservo.write(160);}
if (toggle == 0)
{myservo.write(65);
Serial.print("not"); // Keeps prinitng not until timmer is complete
}
if (toggle == 3)
{myservo.write(110);} // Move to switch off possition
if (digitalRead (11)== HIGH ) // Button switches
{ toggle=1;
Buttons = 1;
timmer = millis();}
if ((millis() - lowreset )> timmer && Buttons == 1 )
{ toggle = 3;
Buttons =0; } // Sets the servo back to center after time out Door up
if (digitalRead (12)== HIGH ) // Button switches
{ toggle=0;
Buttons = 1;
timmer = millis();}
if ((millis() - lowreset )> timmer && Buttons == 1 ) // and or statment
{ toggle = 3;
Buttons =0; } // Sets the servo back to center after time out Door up