Hi all, first project and already in trouble.
I want to build an right left signaller for my car. I mean Indicators. I have two switches on my steering wheel. Left and Right. (I don't have space in my car for the normal stalk on the steering column.)
If I press left, I want the system to check if Left is on, and switch it off. If it is off, switch it on. But if I pressed it briefly, say a third of a second, I want it to be on for 2 seconds and go off automatically.
If I press Right and left is on, I want left to go off and right to go on.
I tried it with a modified debounce, but ran into trouble and then I found the swPressed routine, so I tried that. Did not work because I have two switches that can be pressed.
So I think I will be using the following pseudo code:
Set all the pins start loop Check state of switch1 If low, and time1 is empty, set time1 to now else set timediff1 to now-time1 //So this will loop until switch1 becomes High If switch1 is High and 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 for 2 seconds // thought of a simple delay() but that will mess up the timer end of all Ifs timediff1=0 time1=0 Same checks for switch2 End of loop
That's what I am thinking of doing. Or is there an easier way?
I was thinking of doing the actual checks of the timediff in a separate function, pull it out of the loop. Good idea?
I thought it would be easy, but I am used to event driven software. So it is harder then I thought. Especially as there are two switches.
I have read all the stuff on interfacing it to relays and so, I think I got that sussed. But this realtime stuff, whew.
I would love your comments on this try. I am sure it is going to be messy, but this was all I could come up with.
Thanks in advance