neu-rah / ArduinoMenu

Arduino generic menu/interactivity system
GNU Lesser General Public License v2.1
951 stars 191 forks source link

[Q] Delay between TOGGLE #277

Closed leikoilja closed 4 years ago

leikoilja commented 4 years ago

Hey all. Thank you for the amazing library.

I have tried finding it in documentation, but don't seem to find anything about how to make a slight delay between TOGGLE options?

My problem is that when i press the button it changes the state like 5 times while i hold the button. A slight delay between button press of like 5-10ms would perfectly work here i guess. Instead of me introducing a custom delays is there any configuration option for that?

neu-rah commented 4 years ago

Hi!

I avoid that by limiting the times that .poll is called per second

10 times = 100ms delay

leikoilja commented 4 years ago

Ou, that's a good suggestion. Thank you, @neu-rah. Could you please share a quick reference how to do it?

neu-rah commented 4 years ago

of course, ex: inside loop doing a minimal delay of 100ms, this wont be correct near millis overflow (that happens about every 5 days, but you get the point)

static unsigned int next=0;
if (millis()>=next) {
  nav.poll();
  next=millis()+100;
}

please note that I've not compiled this

leikoilja commented 4 years ago

Thank you, @neu-rah, for help! :+1:

I don't know if i should open another question ticket, but would you please be so kind to help me to find out if there is any method to check for button press? I am wondering if i can monitor which button was pressed inside of idle_function? :smile: In my use case i want to do an action if a user has clicked "OK" button while idle_function was running. Cause currently if any of the buttons pressed during idle_function it will simply return to the menu. I am more thinking if there is any method like wait_until_button_is_pressed()

I think i have got an answer for my own question from this line in docs you have to manage input on your own and activate the menu again when needed Thanks