Arduino Nano have a small "reset button" on board. Also there are new Arduino "Nano 3" one-side boards which also have a similar small button. https://aliexpress.ru/item/32242048437.html
Can I use it somehow for my tasks as turn Arduino on and off by a long press, loop pausing by a short press, change mode by a double ckick, etc?
It is possible to use the reset button for some things. In the most simple usage, the code in setup() will run every time you press the button. Even this is a little bit inconvenient though because there is a delay between reset and setup() running while the bootloader code waits for an upload to start and then times out when no upload is initiated. You can work around that by connecting an ISP programmmer and doing a Sketch > Upload Using Programmer to erase the bootloader, but then you'll need to always do your uploads via ISP after that because the bootloader is required to do the normal upload via the USB socket.
Double click detection is possible. The way you would handle this is by setting a flag in a specific address of the the non-volatile EEPROM memory when setup runs, then unsetting it after some time has passed. Then if you read that address in setup() and find the flag is set you know there were two resets within the given duration.
As for long and short press, the only way to do that would be to disable the reset, which allows you to use it as a normal I/O pin, but the reset is required for uploads, so it's not something most people would want to do.
It's definitely cool to think out of the box for how to do things with the bare minimum amount of resources, but at the same time you'll find that this reset button thing is only useful in a very limited number of applications compared to just wiring up a button normally.
Dear pert, thank you very much for a such comprehensive and fast answer! +rep!
But the main conclusion that I make from your explanation - DON'T fk with reset button! ;D
OK, I will prefer to add and external button or keyboard.
PS I'm often just amazed how millions of users-people live with something which is a normal-standard but for me is ovbiously incomplete - for example it's obvious that EACH Arduino MUST HAVE at least 1 easily programmable LED and 1 easily programmable control button on board. Will wait for updates at 3000 century.
You're welcome. I'm glad if I was able to be of assistance.
When it comes to the LED, I think you already have your wish. I can't remember an Arduino board that doesn't have a built in LED. As for the button, I suppose it would do no harm on the boards with space, but there simply isn't room for it on the smaller boards. I usually put my finished projects in an enclosure, meaning there would not be access to a built-in button, so it would be useful mainly for experimentation and development stage on projects that happened to need a button. What you could do is create a button shield. There is actually one for the WeMos D1 Mini form factor and a more complex "Joystick shield" with buttons for the Uno form factor, but a custom one would be an easy and fun project.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.