Hello,
This is my code for handling two buttons connected to ADC input.
It works fine, and what was most important, it prevents repeated key action -
user has to release the button and press it again, to call needed action again.
However, there are quite a lot of variables, and their number will double with
more buttons being added.
So maybe there is a way to make it simpler, while still maintaining
"do not repeat action" functionality?
Code:menu: 'main loop for button handling adcin 1, adcval 'read keys if adcval=255 then n1=0: n2=0: left=0: right=0 'if no key, then reset both button variables if adcval<10 then left=left+1 'detect button presses if adcval>100 and adcval <130 then right=right+1 'detect button presses if left>100 and n1=0 then 'if button pressed enough and it was not pressed before left=0 n1=1 gosub action1 'button 1 tasks endif if right>100 and n2=0 then 'if button pressed enough and it was not pressed before right=0 n2=1 gosub action2 'button 2 tasks endif pause 1 'input delay goto menu




Bookmarks