Shop OBEX P1 Docs P2 Docs Learn Events
AND logic in PBASIC? — Parallax Forums

AND logic in PBASIC?

meredth78meredth78 Posts: 18
edited 2006-03-31 00:59 in BASIC Stamp
hi guys,
i need to write a conditional AND logic statement.· i am trying to control a series of leds depending on the postion of spdt on1-off-on2 switch and a seperate·input signal. something like...
switch position on1· =>· if pin1 and pin3·= high, then·pin 4 = high
switch position on2· =>· if pin2 and pin3·= high, then pin 4 = high
switch position·off · =>· if·pin3·= high, and pin1 = low,·and pin2 = low, then pin 4 = high

i'm sure there are a multitude of better ways to do this and i am open to any and all possibilities. i haven't·been programming long enough·to know what will and won't work, yet. what i am trying to do is change the flash rate of an led to one of three options using the same triggering input but changing the switch position.

thanks fellas

Comments

  • SSteveSSteve Posts: 808
    edited 2006-03-30 19:43
    Build yourself a truth table. Here's how I interpret your description.
    in1    in2    in3    out4
    0      0       1        1
    0      1       1        1
    1      0       1        1
    1      1       1        not possible
    X      X       0        0
    
    


    If that's correct, then all you need for your statement is "out4 = in3". Somehow that doesn't seem like what you really want.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • PARPAR Posts: 285
    edited 2006-03-31 00:59
    SSteve said...
    Build yourself a truth table. Here's how I interpret your description.
    in1    in2    in3    out4
    0      0       1        1
    0      1       1        1
    1      0       1        1
    1      1       1        not possible
    X      X       0        0
    
    


    If that's correct, then all you need for your statement is "out4 = in3". Somehow that doesn't seem like what you really want.

    in1····in2····in3····out4················· Flash Rate
    0······0·······1········1······················· Rate A
    0······1·······1········1······················· Rate B
    1······0·······1········1······················· Rate C·············
    1······1·······1········not·possible
    X······X·······0········0······················· Behavior not specified by meredth78 (e.g.,
    ······························································· LED off?; on at previous rate?, ...?)

    So, depending on how the program is structured to produce the several flash rates,·would suggest how·you'd have to factor in the actual value of in1 and/or in2.

    Only if Rate A = Rate B = Rate C would it be sufficient to know just in3 (ignoring the undefined ·case of what to do when in3 is 0).

    PAR
Sign In or Register to comment.