How to use push button to input value

HI I'M DOING A PROJECT USING ARDUINO
AND I WANT TO GIVE INPUTS LIKE A CHARACTER
INTO AN ARRAY USING A SINGLE PUSH BUTTON
(if press length > 0.6 s means one value if < 0.6 means another value )
AND I WANT TO COMPARE IT WITH ALREADY DECLARED VALUE.

On forums like these, "help" means that you should show what you've tried already... then ask for specific help on the parts that don't work. So, back to you.

(And please stop SHOUTING)

sorry that's the starting of my project,without that i can't start it,i mean i'm stuck at the beginning.

Here is simple class I wrote that detects when button is pushed, released or held GitHub - KillzoneKid/PushButton: A simple class to handle multiple push buttons you might find suitable

1 Like

Hello
Describe your project in simple words and that very simple.

I just want to make a door unlock system using Morse code as input.

Hello
take some time and search for morse decoder in the WWW.

The problem for me is i want to get input from the push button
like if button is pressed ( < 0.6 sec) means i want to input ' . ' inside and an array
and if the button is pressed ( > 0.6 sec) means i want to input ' _ ' inside the array and want to check(inputArray[ ] == password[ ] ) with the already declared array.if it matches means door will open otherwise it won't.

so i only need a way to input the characters into the array using push button

Which won't work, but let's put that aside for a bit.

Yeah, clear. So here's what you do:

  • Detect when the button is pressed. If so, save the time (use millis()).
  • Ignore additional releases/presses for, let's say, 25 milliseconds or so (debounce)
  • Detect when button is released. Subtract previously recorded time from current millis(). This gives you the time between press and release in milliseconds.
  • Again ignore additional presses/releases for 25 milliseconds (debounce)

Easy peasy. What's holding you back from writing a sketch and giving it a try?

The reason we're going back and forth a bit here is that you keep restating what you want to do. We all know what you want to do. The reason you're stuck is because you're not starting with your project. Get going already!

I think you meant detect when the button becomes pressed rather than is pressed and similarly for the release

Yes, that's a more accurate formulation.

You and I both knew exactly what you meant, but I suspect that a beginner might not so it is better to be specific

Absolutely, you're right!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.