hi,
IMHO the current Btn functions are rather weird and actually should be re-designed.
Just for beginners already a 2nd parameter
in a read-button-function is totally confusing at all, and for advanced members it's not
necessarily needed.
To my opinion, the function should be
which
scans and returns 0 or the Btn code of the currently pressed Btn without waiting for a Btn to be hit or released.
if no button is pressed, it returns 0 (zero) which is equal to FALSE, and if any different value is returned in case there IS a btn pressed, it returns the specific btn code >0 which implements TRUE.
With this design you alternatively may evaluate both the specific Btn-Code and may use it just like a boolean expression
Code: Select all
char BtnValue=ButtonPressed(); // assigns the code of the specific Btn which is pressed
if (ButtonPressed()== Btn1) // asks if just Btn1 is pressed
if (ButtonPressed()) // asks if ANY a Btn is pressed
The other (completely different)
counter functionality should be done by the specific 2nd function
Code: Select all
void ButtonResetCount(const byte btn);
which already exists.
BTW:
is a stdio function that should not be forgotton in this context.
IIRC getchar()
waits until a Btn is pressed and then until it's released again.
With this re-designed function
char ButtonPressed() together with
char getchar() we would have the functionality and convinence that would be desirable.
Further both functions could be easily extended to be able to read 2 or more Buttons being pressed simultaneously if also the btn scan codes will be adjusted:
Code: Select all
Button ScanCode
btn[1] = 1
btn[2] = 2
btn[3] = 4
btn[4] = 8
5 = btn[1] + btn[3] // pressed simultaneously
14= btn[2]+ btn[3] + btn[4] // pressed simultaneously
an additional function
may enhance this analogically
ps:
@admins:
both muntoo's post and my widening one are actually NXC issues, not Bricxcc issues. Maybe you can move them to the NXC wishlist if you wish