Servo as a door lock, How can I ignore a button until later in the program?
hi everyone!
i working on keepsake box uses mini servo lock door
(minimum security more prop proposal)
the sketch have created works in general sense, need little
guidance.
button 2 (which closed when door closed , returns servo to
the locked position) depressed when circuit powered (because
the door closed @ beginning of cycle) , result, keeps
the arduino responding button 1 (which high signal
from source external arduino) opens lock. want
to cycle locked / unlocked leds using pwm not sure
park additional code. i include sketch, in @ least finding
the answer awesome.
thanks!
george
i working on keepsake box uses mini servo lock door
(minimum security more prop proposal)
the sketch have created works in general sense, need little
guidance.
button 2 (which closed when door closed , returns servo to
the locked position) depressed when circuit powered (because
the door closed @ beginning of cycle) , result, keeps
the arduino responding button 1 (which high signal
from source external arduino) opens lock. want
to cycle locked / unlocked leds using pwm not sure
park additional code. i include sketch, in @ least finding
the answer awesome.
thanks!
george
quote
// dac box servo program rev4
// by: george suprenant
// arduino community
// 2012
#include <servo.h>
servo myservo; // create servo object control servo
int pos = 20; // variable store 1st servo position locked
int pos1 = 120; // variable store 2nd servo position unlocked
int buttonstate1 = 0; // initial state of dac button off
int buttonstate2 = 0; // initial state of door button off
const int btn1 = 2; // nubmer of dac pin
const int led1 = 3; // number of locked led pin ~
const int btn2 = 4; // number of door switch pin
const int led2 = 5; // number of unlocked led pin ~
int brightness = 0; // how bright led is
int fadeamount = 5; // how many points fade led by
void setup()
{
pinmode(btn1, input); // set btn1 input
pinmode(led1, output); // set led1 output
pinmode(btn2, input); // set btn2 input
pinmode(led2, output); // set led2 output
myservo.attach(9); // attaches servo on pin 9 servo object
myservo.write(pos); // physicaly sets servo locked position (had problems servo twitching 30+ deg on startup)
digitalwrite(led1, high); // turns on locked led
}
void loop()
{
buttonstate1 = digitalread(btn1); // @ dac pin
buttonstate2 = digitalread(btn2); // @ door switch
if (buttonstate1 == high) { // if dac pin high then,
myservo.write(pos1); // move servo unlocked position
digitalwrite(led1, low); // turn locked led off
digitalwrite(led2, high); // turn unlocked led on
delay (2000); // wait 2 sec prevent door switch bounce
} else if (buttonstate2 == high) { // if door closed switch high
delay (2000); // wait 2 sec prevent lock damage , make sure door closed
myservo.write(pos); // move servo locked position
delay (500); // wait 1/2 sec before door locked led going high
digitalwrite(led2, low); // set door unlocked led low
digitalwrite(led1, high); // set door locked led high
}
}
i don't understand question is. problem sketch see use of delay. way might loose opening signal if waiting door being locked. try eliminate these storing time of event , checking against millis().
i don't know why wanna display boolean information (locked/unlocked) using pwm (which kind of analog output). what's intention there?
i don't know why wanna display boolean information (locked/unlocked) using pwm (which kind of analog output). what's intention there?
Arduino Forum > Using Arduino > Project Guidance > Servo as a door lock, How can I ignore a button until later in the program?
arduino
Comments
Post a Comment