Shop OBEX P1 Docs P2 Docs Learn Events
Assign 6 inputs in one variable — Parallax Forums

Assign 6 inputs in one variable

DeividDeivid Posts: 2
edited 2008-06-17 04:12 in BASIC Stamp
Hi everybody

I can't figure out how to assign 6 ports in one variable.

I've a basic stamp 2 with P3-P4-P5-P6-P7-P8 as inputs.

My idea is to get a event number from this ports, for example if:

P3=1
P4=0
P5=1
P6=1
P7=0
P8=1

event = %101101 = 45

So knowing the value of event, can i work with this code:

rutine1:

IF (event < 1) THEN do_something
event=event - 1
HIGH LED 'just an example
PAUSE 250
LOW LED
GOTO rutine1

do_something:
some code ' here jump when the led has timed on/off "event value" times

Thanks
Deivid

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-06-15 00:50
    You can assign 4, 8 or 16 pin states to a variable of the correct size. Look in the editor help file under Memory and Variables.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-06-15 04:20
    Deivid,
    ·
    You could say something like...
    ·
    event = INS
    ·
    ...To capture the entire 16-Bit port.· Then you could mask the·pins you are interested in with something like this...
    ·
    event = event & %0000000111111000
    ·
    ...At this point you could use the data just as it is, or you can shift it right by 3 to justify the data with something like this...
    ·
    event = event >> 3
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • DeividDeivid Posts: 2
    edited 2008-06-17 04:12
    Thanks Beau Schwabe for your suggestion, I had to change pin configuration, to use only one byte, I looked the editor help file under Memory and Variables as Franklin said, and l came up with this code:


    DIRL = %01000000
    A         CON   20
    porta    VAR  Word           
    event     VAR  porta.LOWBYTE
    
    Get_Event:
      compare = %00111111
      event = evento & compare   
    
    IF event = 0 THEN Main
     
    Mode_1:
                               
      event = event - 1                 
      PULSOUT A,3                      
      IF (event > 1) THEN Mode_1                           
      GOSUB Mode_2
    
    
    



    if event=5 (%00000101), I got 4 pulses in A
    should this works?

    PS: Right now I haven't a Basic Stamp, this is for a project in classroom.

    Thanks
    Deivid
Sign In or Register to comment.