988Views15Replies

Author Options:

I need help with coding a car cruisecontrol and Arduino Leonardo (HID)? Answered

Hi all, I have a challenge I cant solve, I need your help!

I have a car cruise control lever I want to connect to an Arduino Leonardo and have it act like a keyboard (HID).

It has only two wires, 3 push buttons and one toggle switch. I do know the input voltage is 5 volt and every button has its own resistor causing different voltages to come out when used. This way the car computer knows what has been pressed.

I have 3 switches:

1: Acc (Cruise Control Accelerate speed)
2: Ret (Cruise Control Retrieve speed)
3: Res (Cruise Control Resume from last speed)

I have one toggle Switch:

Cruisecontrol ON/OFF

I want the ON/OFF to toggle a keyboard character "C" when used.
I want button 1 to send a "7"
I want button 2 to send an "8"
I want button 3 to send a "9"

The code should pause after each change (no loop). The 10k Restistor is a pull-up resistor for debounce.

Anyone?

Project: https://hackaday.io/project/8448-real-dashboard-truck-simulator

Discussions

0
None
steveastrouk

Best Answer 3 years ago

You need to use an analog input then. "Debouncing" doesn't happen by adding a resistor at random.

Your Cruise switch has only two output wires ? Correct ? You will need to feed it FROM a resistor to the 5V supply, connecting the other to ground. Measure the voltage between the end of the resistor and the ground line. It should vary as the buttons are pressed.

Steve

0
None
Jeroenv26steveastrouk

Answer 3 years ago

Ok, and do you also know code to get my stuff going?

0
None
steveastroukJeroenv26

Answer 3 years ago

PS. Start with a minimal program that reads the A/D and prints a value to the screen 2 times a second.

0
None
Jeroenv26steveastrouk

Answer 3 years ago

Here is a start I made. It is a mix of the Arduino Ohm Meter Tutorial and my own Scania Retarder code. tinyurl.com/ho2me6w

I guess it needs booleaans and if/eleses and stuf to get keyboardprints and no-loop.

0
None
steveastroukJeroenv26

Answer 3 years ago

Get the naked button press values, and post them.

acc= ?

res=?

etc, don't bother with the combinations.

There is a trick you can do to read the results easier.

0
None
Jeroenv26steveastrouk

Answer 3 years ago

here they are:

Vout:

OFF =
4.30v

ON =
4.68v

ON RET =
4.83v

ON RES =
4.92v

ON ACC = 4.97v

Val
= volts x 1023 / 5 = :

OFF =
880

ON =
958

ON RET =
988

ON RES =
1007

ON ACC = 1017

Average
VAL:

OFF (880-0)
/ 2 + 0 = 440

ON (958-880)
/ 2 + 880 = 919

ON RET
(988-958) / 2 + 958 = 973

ON RES (1007-988) / 2 + 988 = 998

ON ACC (1017
– 1007) / 2 + 1007 = 1012

0
None
steveastroukJeroenv26

Answer 3 years ago

Check your PMs and ignore my last comment about doing On+RES etc ;-)

0
None
steveastroukJeroenv26

Answer 3 years ago

When you say "on average", are they fluctuating much ?

0
None
steveastroukJeroenv26

Answer 3 years ago

Yes, but I don't generally write other people's code for them. Start out with a standard Leonardo keyboard program. Instead of keypresses, read the A/D converter. Measure the output and record that for each switch position, then when a key is pressed, and the A/D output changes, convert the level into the appropriate keypress for the rest of the keyboard program.

You shouldn't have to write much code.


Steve

0
None
Kingly2212

4 months ago

Hey my friend, how’s it going, I was wondering if you’ve got the code for this program. I have the similar problem. And I’d be appreciated if you could help me with this.my E-Mail-Adresse is h.soltani6022@gmail.com

0
None
Downunder35m

3 years ago

I would say post it as an Instructable here instead of asking for advise on project you publish elsewhere ;)

0
None
Jeroenv26Downunder35m

Answer 3 years ago

I didn't wanted to spam the indestructibles website with an unfinished project. I will post all of my individual steps once finished on this website ;)