help with rotary encoder, code
sejasti123
Posts: 3
in BASIC Stamp
I have an incremental encoder and I try it using the basic stamp.
The tests went well but I have doubts regarding a line of code.
' =========================================================================
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ I/O Definitions ]
' A Output Connects To P0
' B Output Connects To P1
'
[ Variables ]
oldBits VAR Nib ' Previous State Of I/O Pins 0 - 3
newBits VAR Nib ' Current State Of I/O Pins 0 - 3
direction VAR Bit ' Direction Encoder Is Turned
counter VAR Word ' Counter
'
[ Initialization ]
OUTS = %0000000000000000 ' Set All Output Pins Low
DIRS = %1111111111111100 ' I/O Pins 0 - 1 Inputs
newBits = INA & %0011
'
[ Program Code ]
Main:
DO
' newBits = INA & %0011 ' Get State Of I/O Pins 0, 1
' IF newBits <> oldBits THEN ' Have Bits Changed?
' direction = newBits.BIT0 ^ oldBits.BIT1
counter = counter - 1 + (2 * direction)
DEBUG HOME, DEC5 counter ' Show New Counter On DEBUG Screen
oldBits = newBits ' Update oldBits
' ENDIF
LOOP
'STOP
What does INA mean?
Why changing it to INB or INC nothing happens and the program is still normal.
The tests went well but I have doubts regarding a line of code.
' =========================================================================
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ I/O Definitions ]
' A Output Connects To P0
' B Output Connects To P1
'
[ Variables ]
oldBits VAR Nib ' Previous State Of I/O Pins 0 - 3
newBits VAR Nib ' Current State Of I/O Pins 0 - 3
direction VAR Bit ' Direction Encoder Is Turned
counter VAR Word ' Counter
'
[ Initialization ]
OUTS = %0000000000000000 ' Set All Output Pins Low
DIRS = %1111111111111100 ' I/O Pins 0 - 1 Inputs
newBits = INA & %0011
'
[ Program Code ]
Main:
DO
' newBits = INA & %0011 ' Get State Of I/O Pins 0, 1
' IF newBits <> oldBits THEN ' Have Bits Changed?
' direction = newBits.BIT0 ^ oldBits.BIT1
counter = counter - 1 + (2 * direction)
DEBUG HOME, DEC5 counter ' Show New Counter On DEBUG Screen
oldBits = newBits ' Update oldBits
' ENDIF
LOOP
'STOP
What does INA mean?
Why changing it to INB or INC nothing happens and the program is still normal.
Comments
-Phil
Thank you so much guys,