Key management problems

Hello,

I'm trying to create an alarm clock on andruino uno, but I'm struggling with buttons. My problem is that I cannot write a code which is perceives the pushes. Basicly my code was only working when I pushed the button, as soon as I released it it went back to the regular stand. I would like to use switch-case for it. I can copy the code in comment if its need.

Thanks for the help.

The trick is to get away from the basic examples which test if the button is currently pressed, to write some code that does an action when the button becomes pressed. To do this you need to know that the button wasn't pressed the last time you looked at it but now it is pressed.

Yes, I figured it out. But the problem I cannot find out that type of code alone, thats why I wrote here.

I have a small library in my code repository that implements that type of functionality. Feel free to download and use or learn from it. This is a very common requirements and it was worth creating reusable code for my own projects.

Link in the signature block below.

Yes, I figured it out. But the problem I cannot find out that type of code alone, thats why I wrote here.

The state change detection example does exactly that.

3

I checked your site, but I did not understand too much from your codes, probably because I am newbie. I would apriciate if you could tell me which part of which code is useful to my problem.

4

I checked it but I do not understand all of the details. Plus this Serial thing is totally disunderstandable for me (I read how it is work tho)

I checked it but I do not understand all of the details.

It's a pretty simple example. By keeping track of the state last time, you can tell whether the state this time is the same, or not. If there is some part of the code that you don't unerstand, you have to be more specific.

would apriciate if you could tell me which part of which code is useful to my problem.

The library that would be useful is the KeySwitch library. It implements the sort of algorithm being described by PaulS. If you can't understand that library then the other examples mentions may be easier for you.