help with rotary encoder, code

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.

Comments

  • 3 Comments sorted by Date Added Votes
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,021
    edited June 1 Vote Up1Vote Down
    INA is a pseudo-variable that returns the state of the lower 4 I/O pins, packed as 4 binary bits, P0 being the least-significant. If the pin is high, its bit will return as a 1; otherwise, 0.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • INA means Input pins 3..0. INB means 7..4. And so on. The program would still compile, but would be using the wrong inputs.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
    Cool, CA, USA 95614

  • Thank you so much guys,
Sign In or Register to comment.