how to cumulate 2 actions
hello, newbies in arduino,
trying program these actions:
1-enter secret code on keypad
2-if right code entered, blink led while waiting for…
3-a touch sensor activated finally...
4-keep led on , unlock door
can't cumulate code , sensor unlock magnet solenoid
if can light lantern,
code attached below
trying program these actions:
1-enter secret code on keypad
2-if right code entered, blink led while waiting for…
3-a touch sensor activated finally...
4-keep led on , unlock door
can't cumulate code , sensor unlock magnet solenoid
if can light lantern,
code attached below
ok. sketch moves through number of states.
0 - waiting more kepresses. finished when recent 4 (or six) keypresses match code
1 - waiting touch sensor. finishes when touch sensor acivated (go state 2), or when there timeout (go state 0).
2 - keeping door unlocked. finishes when … dunno. going keep door unlocked set amount of time? going sense when door opened. , go 'locked' mode when closes again?
of course, have write various functions main function invokes.
0 - waiting more kepresses. finished when recent 4 (or six) keypresses match code
1 - waiting touch sensor. finishes when touch sensor acivated (go state 2), or when there timeout (go state 0).
2 - keeping door unlocked. finishes when … dunno. going keep door unlocked set amount of time? going sense when door opened. , go 'locked' mode when closes again?
code: [select]
enum state {
entering_code = 0,
waiting_touch_sensor = 1,
door_unlocked = 2
}
state = entering_code;
void loop() {
switch(state) {
case entering_code:
read_the_keypad();
if(valid_code_entered()) {
start_blinking_the_led();
start_touch_sensor_timeout();
state = waiting_touch_sensor;
}
break;
case waiting_touch_sensor
if(touch_sensor_timeout_exceeded()) {
stop_blinking_the_led();
reset_the_keypad();
state = entering_code;
}
else if(touch_sensor_sensed()) {
stop_blinking_the_led();
unlock_the_door();
start_unlock_timeout();
state = door_unlocked;
}
else {
make_the_led_blink();
}
break;
case door_unlocked:
if(door_unlock_timeout_exceeded()) {
lock_the_door();
reset_the_keypad();
state = entering_code;
}
break;
}
}
of course, have write various functions main function invokes.
Arduino Forum > Using Arduino > Programming Questions > how to cumulate 2 actions
arduino
Comments
Post a Comment