Shop OBEX P1 Docs P2 Docs Learn Events
Setting up variables — Parallax Forums

Setting up variables

johntechjohntech Posts: 8
edited 2009-03-30 04:50 in BASIC Stamp
I have 5 IR detectors that I am monitoring. I am using a BS2 and using pins 1 - 5 as input pins.
When they are not blocked all the inputs are low (0), when blocked they are high (1)
Right now I am using a ·IF/THEN·tree to see which one(ones)·is (are)·blocked.

I am reading the Basic Stamp Syntax and Reference Manual
I am wondering·how to set a variable ex:

IRBlocked· var nib

then read the 5·inputs as· either 1's or 0's· ex: 00000 - 11111 or any combination between in the group

and then use a select case statement to display which ones are blocked depending on the state of the
5 digits.

So if the first one was blocked IRBlocked would equal "10000"
The last two blocked would equal "00011"

Any help would be appreciated

Thank you

John

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-03-29 22:14
    First, a nib is 4 bits and then look at bit variables ina inb .... that should give you a start

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-03-29 22:29
    There are 32 cases. Maybe the CASE statement is not what you want. Reading and displaying the inputs is pretty easy:
    myIR VAR Byte
    DO
      myIR = inL >> 1 & %00011111
      ' that reads the inputs, shifts the result one bit right, and masks off 5 bits.  State of in1 to in5 now in myIR
      DEBUG BIN5 myIR, CR   ' display as 5 binary bits
      NAP 5
    LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • johntechjohntech Posts: 8
    edited 2009-03-30 01:31
    Thank you Stephen for your reply.

    I guess I need to do some more reading on the ina and inb commands and differences between NIB and the BYTE


    Thank you Tracy for the code.

    I'll try your code and read up on the commands in your line

    ····· myIR = inL >>1 & %00011111

    If I am looking for a certain state of the IR's· say "11011"
    then I can use a simple IF/THEN statement·like

    IF myIR = "11011" THEN OUT 10

    I'll have to try that and see if it works


    Thanks again to both of you

    John
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-03-30 01:59
    No, test myIR like this,
    IF myIR=%11011 THEN HIGH 10

    It only becomes a string for display PBASIC when formated by the BIN5 myIR modifier. PBASIC does not have string operators or string variables.

    OUT 10 is not a valid syntax. You can say,
    OUTPUT 10 ' makes p10 an output
    OUT10=10 ' makes p10 high
    or
    HIGH 10 ' makes it output and high all at once.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • johntechjohntech Posts: 8
    edited 2009-03-30 04:50
    So you use the byte data format %XXXXX for what ever combination you are looking for.... I see

    It's back to the book for more reading

    Thank you Tracy

    John
Sign In or Register to comment.