BeanieBots
Moderator
Using PE 5.2.0 & 18X V8.6
I've always thought of the button command as a bit of a "lost soul" and never really gave it much thought until recently.
For debounce, a simple test input and pause does the job, however, when recently trying to create a menu system I thought I'd explore the "repeat" feature.
This proved to be quite tricky and I don't think the description given in the manual helps. Here's what I found:-
As per the manual:
Button Pin,DownState,Delay,Rate,Var,TargetState,Address
The first thing I got was a syntax error. Fortunately, the error message clearly explained what the problem was. I'd already set up all my symbols for my I/O pins and thought I'd replace "Pin" with the symbol I'd used for that input. But no, it doesn't work like that It didn't want "pin6", it just wanted the "6", so my symbol "Button_A" (which is used elsewhere) can't be used in the Button command line. Why is this convention?
Then the fun started with "Delay" and "Rate".
I put in some nominal values of 128 for each.
Couldn't distinguish between the first push and a repeat. Tried all sorts of values and combinations to no avail.
It wasn't until I started to debug "Var" that I realised what was actually going on. "Delay" is actually a COUNT of how many times you've been through the loop. In a tight loop, the "Delay" is virtually nothing.
Having worked that out and inserted a pause in my loop, things were looking up until I tried to make the pause as small as possible and use the largest "delay".
The manual is quite clear, "delay" can be 0 to 255.
Except 255 is a 'special' value which prevents the repeat from working at all. All you get is one jump to address when "delay"=255. 254 is the maximum value you can have. This is actually a useful feature and should be explained in the manual.
So, here's my description of how "Button" works.
"Pin" uses the OUTPUT convention, NOT the input convention.
"Delay" is how many times the command must be passed before it does the first repeat.
"Rate" is how many times the command must be passed before it subsequent repeats.
"Var" must be set to zero before the command is used (as explained in the manual) but that must be a once only setting. It must be done before you enter the loop which scans your button.
Maybe this is all obvious to everyone else, but it kept me bemused for quite a while
I've always thought of the button command as a bit of a "lost soul" and never really gave it much thought until recently.
For debounce, a simple test input and pause does the job, however, when recently trying to create a menu system I thought I'd explore the "repeat" feature.
This proved to be quite tricky and I don't think the description given in the manual helps. Here's what I found:-
As per the manual:
Button Pin,DownState,Delay,Rate,Var,TargetState,Address
The first thing I got was a syntax error. Fortunately, the error message clearly explained what the problem was. I'd already set up all my symbols for my I/O pins and thought I'd replace "Pin" with the symbol I'd used for that input. But no, it doesn't work like that It didn't want "pin6", it just wanted the "6", so my symbol "Button_A" (which is used elsewhere) can't be used in the Button command line. Why is this convention?
Then the fun started with "Delay" and "Rate".
I put in some nominal values of 128 for each.
Couldn't distinguish between the first push and a repeat. Tried all sorts of values and combinations to no avail.
It wasn't until I started to debug "Var" that I realised what was actually going on. "Delay" is actually a COUNT of how many times you've been through the loop. In a tight loop, the "Delay" is virtually nothing.
Having worked that out and inserted a pause in my loop, things were looking up until I tried to make the pause as small as possible and use the largest "delay".
The manual is quite clear, "delay" can be 0 to 255.
Except 255 is a 'special' value which prevents the repeat from working at all. All you get is one jump to address when "delay"=255. 254 is the maximum value you can have. This is actually a useful feature and should be explained in the manual.
So, here's my description of how "Button" works.
"Pin" uses the OUTPUT convention, NOT the input convention.
"Delay" is how many times the command must be passed before it does the first repeat.
"Rate" is how many times the command must be passed before it subsequent repeats.
"Var" must be set to zero before the command is used (as explained in the manual) but that must be a once only setting. It must be done before you enter the loop which scans your button.
Maybe this is all obvious to everyone else, but it kept me bemused for quite a while