Wrestling with 2 switches and timing
hi all, first project , in trouble.
i want build right left signaller car. mean indicators.
i have 2 switches on steering wheel. left , right. (i don't have space in car normal stalk on steering column.)
if press left, want system check if left on, , switch off. if off, switch on. if pressed briefly, third of second, want on 2 seconds , go off automatically.
if press right , left on, want left go off , right go on.
i tried modified debounce, ran trouble , found swpressed routine, tried that. did not work because have 2 switches can pressed.
so think using following pseudo code:
that's thinking of doing.
or there easier way?
i thinking of doing actual checks of timediff in separate function, pull out of loop. idea?
i thought easy, used event driven software.
so harder thought. there 2 switches.
i have read stuff on interfacing relays , so, think got sussed. realtime stuff, whew.
i love comments on try. sure going messy, come with.
thanks in advance
lykle
i want build right left signaller car. mean indicators.
i have 2 switches on steering wheel. left , right. (i don't have space in car normal stalk on steering column.)
if press left, want system check if left on, , switch off. if off, switch on. if pressed briefly, third of second, want on 2 seconds , go off automatically.
if press right , left on, want left go off , right go on.
i tried modified debounce, ran trouble , found swpressed routine, tried that. did not work because have 2 switches can pressed.
so think using following pseudo code:
code: [select]
set pins
start loop
check state of switch1
if low, , time1 empty, set time1
else
set timediff1 now-time1
//so loop until switch1 becomes high
if switch1 high , timediff1 != 0 then
if timediff1> debounce, then
if timediff1 > longlimit, then
check light2
if on, switch off
check light1
if on, switch off, else switch on
else
switch on 2 seconds
// thought of simple delay() mess timer
end of ifs
timediff1=0
time1=0
same checks switch2
end of loop
that's thinking of doing.
or there easier way?
i thinking of doing actual checks of timediff in separate function, pull out of loop. idea?
i thought easy, used event driven software.
so harder thought. there 2 switches.
i have read stuff on interfacing relays , so, think got sussed. realtime stuff, whew.
i love comments on try. sure going messy, come with.
thanks in advance
lykle
quote
i thought easy, used event driven software.
if you're comfortable in event-driven terms, why not make event system? store last known state of system, , fire event when state changes.
code: [select]
#define n 2
byte pins[n] = { 9, 10 };
byte switches[n] = { low, low };
long when[n] = { 0, 0 };
void loop()
{
long = millis();
for (int = 0; < n; i++)
{
byte pushed = digitalread(pins[i]);
if (switches[i] != pushed)
{
if (pushed)
onbuttonpressed(i);
else
onbuttonreleased(i, when[i] - now);
when[i] = now;
switches[i] = pushed;
}
}
}
void onbuttonpressed(byte button)
{
// if button's pushed
}
void onbuttonreleased(byte button, long held)
{
// if button's released
// learn how long held
}i'm not saying complete, or if it's best way go, can adapt whole system work in way want work.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Wrestling with 2 switches and timing
arduino
Comments
Post a Comment