Shop OBEX P1 Docs P2 Docs Learn Events
Checking on status. — Parallax Forums

Checking on status.

PasserbyPasserby Posts: 17
edited 2008-11-27 02:08 in BASIC Stamp
I'm not sure if the topic title is relavent.

I did a sensor design where it reads 1 and 0 and sends the signal to Basic Stamp for reading.

Right now I'm suppose to build 3 more of such designs, and join them together and read them as binary codes.

I know the idea, I checked the index of the Basic Stamp program, but can't seem to find a code that relates to what I wanted to do.

For eg:

' {$STAMP BS2}
' {$PBASIC 2.5}
' Project: GT60-Phone Systen
'======================================================================================
xvar1 VAR Byte
xvar2 VAR Byte
xvar3 VAR Byte
xvar4 VAR Byte
SETUP:
INPUT 1·············· 'Set PIN 1 to INPUT
INPUT 2·············· 'Set PIN 2 to INPUT
INPUT 3·············· 'Set PIN 3 to INPUT
INPUT 4·············· 'Set PIN 4 to INPUT
MAIN:
IF IN1 = 1 THEN xvar1 = 1
IF IN2 = 1 THEN xvar2 = 1
IF IN3 = 1 THEN xvar3 = 1
IF IN4 = 1 THEN xvar3 = 1
BINARYCHECK:
IF xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 1."
IF xvar2 = 1 THEN DEBUG CR, "Binary Code sense a 2."
IF xvar1 = 1, xvar2 = 1 THEN DEBUG CR, "Binary Code sense a 3."
IF xvar3 = 1 THEN DEBUG CR, "Binary Code sense a 4."
IF xvar3 = 1, xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 5."
IF xvar3 = 1, xvar2 = 1· THEN DEBUG CR, "Binary Code sense a 6."
IF xvar3 = 1, xvar2 = 1, xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 7."
IF xvar4 = 1 THEN DEBUG CR, "Binary Code sense a 8."
IF xvar4 = 1, xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 9."
IF xvar1 = 0, xvar2 = 0, xvar3 = 0, xvar4 = 0 THEN DEBUG CR, "Binary Code sense a 0."

This is the idea I have, but I know I can't use the IF - THEN function here.

Any suggestion please? jumpin.gif


Post Edited (Passerby) : 11/26/2008 2:31:46 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-26 02:39
    Instead of "IF x = 1, y = 1 THEN" use "IF x = 1 AND y = 1 THEN"
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-26 02:46
    Hi Passerby --

    I think you could use a single byte, or even a nibble (halfbyte), thus:

    Xvar VAR NIB
    Xvar = INA ' The states of Pin0 through Pin3. INA is defined permanently by the compiler itself.
    debug hex xvar, CR

    Of course, you could just do this:

    debug hex INA, CR


    -- delay --

    I just tried that, and it works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-26 02:54
    I should have mentioned that INA is inputs 0 through 3, INB is inputs 1 through 4, etc.

    If you want all 8 of inputs 0 through 7,

    DEBUG HEX2 INL, CR ' INL is the lower 8 inputs, INH is the upper 8

    If you want all 16,

    DEBUG HEX4 INS, CR ' INS is the word containing all 16 inputs 0-15

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-11-26 03:46
    Carl -

    Small correction. In your message it reads:
    "I should have mentioned that INA is inputs 0 through 3, INB is inputs 1 through 4, etc."

    It should read:
    "I should have mentioned that INA is inputs 0 through 3, INB is inputs 4 through 7, etc."

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-26 04:42
    Bruce Bates said...
    Carl -

    Small correction. In your message it reads:
    "I should have mentioned that INA is inputs 0 through 3, INB is inputs 1 through 4, etc."

    It should read:
    "I should have mentioned that INA is inputs 0 through 3, INB is inputs 4 through 7, etc."

    Regards,

    Bruce Bates

    Oops.· Thanks.· Of course.··Gosh, I'm only 68 -- how bad will it be when I'm old?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • PasserbyPasserby Posts: 17
    edited 2008-11-27 02:08
    Hi Mike Green.

    I had a code written with that function after I posted the code on the forums. The code should work, but I'm not very sure is it my circuit connections being too lose, or is the sensitivity of the transistor too weak.

    I'll try the method listed by Carl Hayes and Bruce Bates before I post here again. Thanks all and really appreciate the helps I recieved in this forums! [noparse]:D[/noparse]

    EDIT:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' Project: GT60-Phone Systen
    '======================================================================================
    xvar1 VAR Byte
    xvar2 VAR Byte
    xvar3 VAR Byte
    xvar4 VAR Byte
    SETUP:
    INPUT 1·············· 'Set PIN 1 to INPUT
    INPUT 2·············· 'Set PIN 2 to INPUT
    INPUT 3·············· 'Set PIN 3 to INPUT
    INPUT 4·············· 'Set PIN 4 to INPUT
    MAIN:
    IF IN1 = 1 THEN xvar1 = 1
    IF IN2 = 1 THEN xvar2 = 1
    IF IN3 = 1 THEN xvar3 = 1
    IF IN4 = 1 THEN xvar3 = 1
    BINARYCHECK:
    IF xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 1."
    IF xvar2 = 1 THEN DEBUG CR, "Binary Code sense a 2."
    IF xvar1 = 1 AND xvar2 = 1 THEN DEBUG CR, "Binary Code sense a 3."
    IF xvar3 = 1 THEN DEBUG CR, "Binary Code sense a 4."
    IF xvar3 = 1 AND xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 5."
    IF xvar3 = 1 AND var2 = 1· THEN DEBUG CR, "Binary Code sense a 6."
    IF xvar3 = 1 AND xvar2 = 1 AND xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 7."
    IF xvar4 = 1 THEN DEBUG CR, "Binary Code sense a 8."
    IF xvar4 = 1 AND xvar1 = 1 THEN DEBUG CR, "Binary Code sense a 9."
    IF xvar1 = 0 AND xvar2 = 0 AND xvar3 = 0 AND xvar4 = 0 THEN DEBUG CR, "Binary Code sense a 0."
    This is the curent code that I have.
    It should be working right, I'll test with some firm connections by soldering it into some board and get the results. [noparse]:)[/noparse]

    Post Edited (Passerby) : 11/27/2008 7:57:01 AM GMT
Sign In or Register to comment.