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?
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
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.
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
). If others like it and find it useful, then they will ask you for improvements and suggest enhancements.
bit like programming styles, editors, ide’s, languages … … …
stephen
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.
…
– add “double-click” functionality.
stephen
stephen
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
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
