Need help with button press and double press functionality, using resistance.

Hi all, I’m working on a project to make use of some resistance based buttons on my steering wheel, however I’m having a little trouble figuring out one aspect of it.

I’ll be reading the analog input of the buttons on a couple analog pins, I haven’t hooked my arduino up to them yet for exact numbers, just the resistance values themselves, and the resistance is about 47k when nothing is pressed, and changes based on whichever button is pressed.

I’m looking for a way that I can detect double and long presses of these buttons, based on checking the resistance, so if it falls within x amount and is pressed twice I can do one thing, or press and hold to do another.

Should be fairly simple but all the examples I can find are for regular push buttons connecting to ground, so I’m not quite sure how to implement it with reading an analog value.

edit: odd, my if statement for checking the resistance isn’t working either, it won’t trigger pin2 for some reason.

val1 = analogRead(radioinput);
Serial.println(val1);
if (val1>=950 && val1<=800) digitalWrite(2, LOW);

maybe it has to do with there being a constant higher reading if I don’t connect a resistor on that input, but I also tried setting val1 to zero if it was the usual output and that didn’t work either.

Man I must be rusty.

my if statement for checking the resistance isn’t working either, it won’t trigger pin2 for some reason.

 if (val1>=950 && val1<=800)

This is an impossible condition. Say the words to your self.

“If val1 is greater than or equal to 950 and val1 is less than or equal to 800.”

cattledog:

 if (val1>=950 && val1<=800)

This is an impossible condition. Say the words to your self.

“If val1 is greater than or equal to 950 and val1 is less than or equal to 800.”

Ah balls not only that but forgot to use { as well. Definitely need to sleep more. Now I just need to get the double press and long press thing to work.

The onebutton library seems to be the right track, I just need to figure out how to make it use a variable/value as an input instead of just a low/high pin state.