Press a button

Rintin
Thu Dec 15, 2016 1:14 am
Hi,

I needed to detect if a button is pressed once, twice or long.

For this I wrote the attached code.

The used pin is configured with the internal pullup resistor.
You only need to connect the button to the pin and ground.

Any suggestions on how to improve the code?


mrburnette
Thu Dec 15, 2016 4:01 am
Any suggestions on how to improve the code?

Not trying to be contrary, but does your code not work as you need it to work? That is, do you need assistance with the code: does it not function in some manner? Or, are you just looking for some critical comments or idle conversation?

Unless your code example is too long to post in code tags (that menu button titled ‘Code’), then pasting between the tags is the preferable way to show code since downloading a Zip, uncompressing, reviewing in an editor …. Well, it is a waste of time.

Ray


RogerClark
Thu Dec 15, 2016 10:06 am
@rintin

This section is not intended for programming questions, its intended for people to post useful STM32 specific code example snippets

Is this even a STM32 specific problem.

If its a general Arduino programming question you would be better off posting to https://forum.arduino.cc/index.php?board=4.0

I’ve a mind to either move this thread entirely to perhaps Off Topic, or perhaps General, as its not really relevant on this forum.


ahull
Fri Dec 16, 2016 10:23 am
Other “Press a button” libraries are available… -> http://playground.arduino.cc/Code/Button

I took a quick look at the code in the three files in the zip file Rintin posted above. Assuming it works as intended, then it looks fine. What I would suggest is that the OP”s question was somewhat vague.

“Any suggestions on how to improve the code?”

Yes, document it fully, stick it on GitHub add some wiki details on how to use it, and perhaps a few working examples with pictures (we all like pictures of blinklights :D ). If others like it and find it useful, then they will ask you for improvements and suggest enhancements.


zmemw16
Fri Dec 16, 2016 9:12 pm
oh how many wheels can i get on my wagon ?
bit like programming styles, editors, ide’s, languages … … …
stephen

stevestrong
Sat Dec 17, 2016 11:03 am
Come on, guys, be gentle with Rintin, I think he did a good job, his code includes more than the Alexander’s (playground) version.
Btw, this is the right place to post code snippets, what he actually did correctly in my view.

What I would propose:
– a github place for this (as Andy also suggested) – @Rintin, can you do this?
– add “double-click” functionality.


ahull
Sat Dec 17, 2016 11:36 am
stevestrong wrote:Come on, guys, be gentle with Rintin, I think he did a good job,

– add “double-click” functionality.

zmemw16
Sat Dec 17, 2016 11:45 am
which side of 7/1954, so i can agree or say behave young man :D

stephen


ahull
Sat Dec 17, 2016 12:24 pm
zmemw16 wrote:which side of 7/1954, so i can agree or say behave young man :D

stephen


zmemw16
Sat Dec 17, 2016 12:46 pm
ain’t got a lawn :D
front is 30ft sq with side path, natural planting and a central square of paving, rear is 70ft x 30ft of non-descript concrete.
60ft of 15ft high of hedge ( a yearly short top and one side trim exercise ) and a WIP fence from other side’s neighbour.

stephen


ahull
Sat Dec 17, 2016 1:28 pm
zmemw16 wrote:ain’t got a lawn :D
front is 30ft sq with side path, natural planting and a central square of paving, rear is 70ft x 30ft of non-descript concrete.
60ft of 15ft high of hedge ( a yearly short top and one side trim exercise ) and a WIP fence from other side’s neighbour.

stephen


Leave a Reply

Your email address will not be published. Required fields are marked *