Buttons problem

Post here first, or if you can't find a relevant section!
Grzegorz70
Posts: 6
Joined: Wed Dec 23, 2020 8:01 pm

Buttons problem

Post by Grzegorz70 »

Hi All,

I would like to ask you very much for help in arduino. I tried to cover the subject with the Button King library because it has a press function without having to play with mills.

The topic is quite simple.

I want to press the SET button and hold for a while (I just used press here) then I go to the settings menu where with the second CHANGE button I change the value of the X variable upwards by 1 plus the usual if after exceeding the value to zero. The third OK button is used to save the set X value and go to changing the Y value. Similarly, with the CHANGE button, I change the Y value up by 1 as above. Pressing the OK button saves the value of the Y variable and exits the settings menu. At any time, pressing and holding the SET button causes exit from the settings and if it was pressed when setting the X variable, nothing changes, but if it was pressed while setting the Y variable value, the previously set X value changes and the Y value does not.

You can do it with regular digitalread, but you'd have to play around with debouncing, timers for that and this press. Maybe you know a library and you can help on this topic. To clarify - the STM32F103 processor, RogerClark Core, so not all standard libraries work without modification.


I will be so grateful for your help
best regards
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Buttons problem

Post by fpiSTM »

Maybe you can try this one:
https://github.com/thomasfredericks/Bounce2

It think it should be compatible with Roger's core.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Buttons problem

Post by mrburnette »

Grzegorz70 wrote: Fri Feb 05, 2021 12:37 pm ...
You can do it with regular digitalread, but you'd have to play around with debouncing, timers for that and this press.
Maybe you know a library and you can help on this topic.
You posted a "word problem" and are looking at a library for a flexible solution. Rather, flowchart your program logic requirements first and then determine if a library is required. Maybe a debounce function for button presses, but before going library searching you need a state diagram.

One of the STM32duino forum member (Roger's time) has a good video on state machines:
https://www.youtube.com/watch?v=nicI7JVq2JQ

Ray
Grzegorz70
Posts: 6
Joined: Wed Dec 23, 2020 8:01 pm

Re: Buttons problem

Post by Grzegorz70 »

Thanks Ray,

Button King library if very flexible. It has click, double click, triple click, press, double press, triple press with configurable press and release time and of course debouncing time. So I could use it in almost all project but my brain goes to sleep :( and I can not understand syntax. Im main loop I put press for one button and it works, I can enter submenu. All things which shoud be done after clicking/pressing are in different voids so there is one void for entering submenu adn second for increasing X value but if I put the code change.isClick() in submenu void, nothing happen. Thats why I've asked if someone used this library. I made it some time ago on regular digitalread function with mills for longpress and it works well on nano. I've found Button King very usefull and I've asked for little help with using it. If no one knows it, I will try to do it myself or just copy part of old code.

Regards,
Grzegorz
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Buttons problem

Post by ag123 »

@Ray is right, a menu is an abstraction / example of that state machine
https://www.arduino.cc/reference/en/lib ... u-library/
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Buttons problem

Post by stevestrong »

Grzegorz70 wrote: Fri Feb 05, 2021 3:56 pm Button King library if very flexible. It has click, double click, triple click, press, double press, triple press with configurable press and release time and of course debouncing time.
...
Thats why I've asked if someone used this library.
First, you have not mentioned this ibrary before.
Second, have you tried one of the examples included in the library?
If yes, does it work?
If not, you sould try one, because as far as I can see, it should work out of the box for STM32, too.
Grzegorz70
Posts: 6
Joined: Wed Dec 23, 2020 8:01 pm

Re: Buttons problem

Post by Grzegorz70 »

Hi Steve,

I've mentioned about it in the first line ;)

Of course I've checked examples. They are works well but only on first level. As I wrote, I can enter setup page and display all items but other buttons are dead. I use one button to go to the setup page where I would like to chcange two variables. Using this library I can enter setup page but how to use other buttons on this page. Library works using function in which you describe what you want to do with each button. So I made a functions which are called when SET button is pressed, when CHANGE button is clicked and when OK button is clicked but when I call CHANGE or OK function they doesn't work. Change function just increase variable and display its new value. At this point I've checked that in setup page buttons are not readed and I don't know why
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Buttons problem

Post by mrburnette »

Grzegorz70 wrote: Sat Feb 06, 2021 8:38 pm ...
Of course I've checked examples. They are works well but only on first level. As I wrote, I can enter setup page and display all items but other buttons are dead.
...
Thus, by your own tests, the library is not working. So, the author states the lib is compatible with STM32 boards and the issue can only be:
- You have implemented code that chokes the library, OR
- The library does not support your current use case or environment
https://github.com/TanPitch/ButtonKing

all worked : test on
Arduino Zero, Leonardo, Uno, Mega, Due
ESP8266 and ESP32
STM32 based boards
Generally, this is where I suggest you attempt to contact the author and send them a copy of your code (assuming s/he is agreeable.) Or, start with a working example and start changing to morph into what you need - noting where things "break."

As for myself, I have never used anything resembling "ButtonKing", rather building my menu systems project-centric in dedicated code for efficiency sake.
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Buttons problem

Post by fredbox »

Coding a working hierarchical menu on a microprocessor is a good coding exercise. There are many ways to get there.
The first thing I would do is to create a flowchart and map out each menu with exactly what you want to happen when buttons are pressed.

I wrote my first menu system for an 8051 about 30 years ago when the 286/Windows 3.0 was the top of the line desktop.
After mapping the menus on a "D" size sheet of vellum, I coded a state machine with each menu item in a separate function.
The main loop consisted of a single function call: (*state_pointer)(). Each menu would scan the switches (up, down, left, right, enter) and change settings or move to another menu as needed. It was simple, efficient and trouble free for the lifetime of the product.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: Buttons problem

Post by stevestrong »

Without an example we cannot guess what can be wrong.
I would suggest to build your code step by step based on one of the working examples.
Analyze the version which is not doing what you expect, and post an issue on the original github site if you are sure you have found a bug.
Otherwise you could share here that version, maybe you overlooked something which we can point out quickly ;) .
Post Reply

Return to “General discussion”