Variable Questions
Hello everybody.
I am trying to understand variables. What I am trying to accomplish.When I momentarily push a button I would like to register that the push buttonhas or has not been pressed in the DEBUG HOME. I am having problems. Cannot getthe input to communicate with the variable. What is your recommendations. Thank you.
' {$STAMP BS2}' {$PBASIC 2.5}
hold VAR Bit
DO
DEBUG HOME
DEBUG ? IN0
DEBUG ? hold
INPUT 0
LOOP
I am trying to understand variables. What I am trying to accomplish.When I momentarily push a button I would like to register that the push buttonhas or has not been pressed in the DEBUG HOME. I am having problems. Cannot getthe input to communicate with the variable. What is your recommendations. Thank you.
' {$STAMP BS2}' {$PBASIC 2.5}
hold VAR Bit
DO
DEBUG HOME
DEBUG ? IN0
DEBUG ? hold
INPUT 0
LOOP
Comments
The program looks okay. The variable "hold" doesn't do anything. A simpler test program is,
DO
DEBUG in0+48 ' prints 0 or 1
PAUSE 100
LOOP
That simply shows a continuous line, 00000011111100000011...
[SIZE=2][FONT=courier new][COLOR=#000000]' {$STAMP BS2} ' {$PBASIC 2.5}[/COLOR] [COLOR=#000000] hold VAR Bit hold = 0 INPUT 0[/COLOR] [COLOR=#000000] DO[/COLOR] [COLOR=#000000] hold = hold | IN0 DEBUG HOME [/COLOR][COLOR=#000000] DEBUG ? IN0 [/COLOR][COLOR=#000000] DEBUG ? hold [/COLOR][COLOR=#000000]LOOP[/COLOR] [/FONT][/SIZE]
But if your input is normally HIGH and goes LOW when you press the button, then use this:
[FONT=courier new][SIZE=2][COLOR=#000000]' {$STAMP BS2} ' {$PBASIC 2.5}[/COLOR] [COLOR=#000000] hold VAR Bit hold = 1 INPUT 0[/COLOR] [COLOR=#000000] DO hold = hold & IN0 [/COLOR][COLOR=#000000] DEBUG HOME [/COLOR][COLOR=#000000] DEBUG ? IN0 [/COLOR][COLOR=#000000] DEBUG ? hold [/COLOR][COLOR=#000000]LOOP[/COLOR] [/SIZE][/FONT]
Once you press the button, hold will retain the state. You will need to clear/reset hold later in your program to capture another button press.