Shop OBEX P1 Docs P2 Docs Learn Events
problems with code. — Parallax Forums

problems with code.

ArchiverArchiver Posts: 46,084
edited 2002-05-28 18:57 in General Discussion
I am trying to take the output voltage from one pin and use that as an input
voltage for another pin. This is going to be used to determine the level of
water in a cup. Basically I need to get the value of pin1 to see if it has
been set high. If it has then I need to turn pin2 to high. From the lines
below I am not sure if I can do

if pin1 = 1 then... ? Or is it looking for an actual voltage value to
compare it to?


Thanks guys!

---- below is my code. Thank you very much! ----


'{$stamp bs1}

output pin0 ' output voltage
high pin0

input pin1 ' waiting voltage.

output pin2 ' toggle voltage.
low pin2



loop:

if pin1 = 1 then pump_off ' Check to see if set high
if pin1 < 1 then pump_on ' Check to see if set low


pump_on:
high pin2
goto pump_on

pump_off:
low pin2
goto pump_off

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-05-28 08:04
    It is easier using IN and OUT command than HIGH, LOW for this task:


    Input 1
    Output 2

    'set output 2 = input 1
    OUT2 = IN1

    That solve it?
    -Martin



    --- In basicstamps@y..., "Henk Visser" <henk@h...> wrote:
    >
    > I am trying to take the output voltage from one pin and use that as
    an input
    > voltage for another pin. This is going to be used to determine the
    level of
    > water in a cup. Basically I need to get the value of pin1 to see
    if it has
    > been set high. If it has then I need to turn pin2 to high. From
    the lines
    > below I am not sure if I can do
    >
    > if pin1 = 1 then... ? Or is it looking for an actual voltage value
    to
    > compare it to?
    >
    >
    > Thanks guys!
    >
    > ---- below is my code. Thank you very much! ----
    >
    >
    > '{$stamp bs1}
    >
    > output pin0 ' output voltage
    > high pin0
    >
    > input pin1 ' waiting voltage.
    >
    > output pin2 ' toggle voltage.
    > low pin2
    >
    >
    >
    > loop:
    >
    > if pin1 = 1 then pump_off ' Check to see if set high
    > if pin1 < 1 then pump_on ' Check to see if set low
    >
    >
    > pump_on:
    > high pin2
    > goto pump_on
    >
    > pump_off:
    > low pin2
    > goto pump_off
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-28 08:06
    martin,

    How would I put that into an 'if' condition so I can branch? ( I am also
    using the BS1 )

    Thanks.



    It is easier using IN and OUT command than HIGH, LOW for this task:


    Input 1
    Output 2

    'set output 2 = input 1
    OUT2 = IN1

    That solve it?
    -Martin



    --- In basicstamps@y..., "Henk Visser" <henk@h...> wrote:
    >
    > I am trying to take the output voltage from one pin and use that as
    an input
    > voltage for another pin. This is going to be used to determine the
    level of
    > water in a cup. Basically I need to get the value of pin1 to see
    if it has
    > been set high. If it has then I need to turn pin2 to high. From
    the lines
    > below I am not sure if I can do
    >
    > if pin1 = 1 then... ? Or is it looking for an actual voltage value
    to
    > compare it to?
    >
    >
    > Thanks guys!
    >
    > ---- below is my code. Thank you very much! ----
    >
    >
    > '{$stamp bs1}
    >
    > output pin0 ' output voltage
    > high pin0
    >
    > input pin1 ' waiting voltage.
    >
    > output pin2 ' toggle voltage.
    > low pin2
    >
    >
    >
    > loop:
    >
    > if pin1 = 1 then pump_off ' Check to see if set high
    > if pin1 < 1 then pump_on ' Check to see if set low
    >
    >
    > pump_on:
    > high pin2
    > goto pump_on
    >
    > pump_off:
    > low pin2
    > goto pump_off


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-28 18:57
    Hi Henk,

    Your own BS1 code is fine, except that it will get stuck in a little
    loop that doesn't ever again test the state of the input pin.

    pumpLoop:
    If pin1=1 then pump_off
    pump_on:
    high pin2
    goto pumpLoop
    pump_off:
    low pin2
    goto pumpLoop

    The stamp, even the BS1, gives you a lot of ways to do things. As you
    surmised, pin1 can have only two values, 0 and 1, and that depends on
    the input voltage being above or below the threshold level of about
    1.3 volts.

    You can write the "if" condition without the equals sign, because the
    Stamp understands any non-zero value as True:

    If pin1 then pump_off ' branches when pin1=1

    You can alternatively use the BRANCH command, which often gives code
    that is easier to read:

    branch pin1,(pump_on,pump_off) ' two states

    Martin's suggestion is the most efficient, because it translates the
    input state on one pin directly to the output state of another pin.
    Here it is in BS1 syntax:

    pins=%00000010 ' set pin1 high, all others low
    dirs=%11111011 ' pin2 is the only input, all others output
    pumpLoop:
    pin1=1-pin2 ' transfer pin, invert (0-->1 and 1-->0)
    goto pumpLoop

    -- regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...


    >martin,
    >
    >How would I put that into an 'if' condition so I can branch? ( I am also
    >using the BS1 )
    >
    >Thanks.
    >
    >
    >
    >
    >It is easier using IN and OUT command than HIGH, LOW for this task:
    >
    >
    >Input 1
    >Output 2
    >
    >'set output 2 = input 1
    >OUT2 = IN1
    >
    >That solve it?
    >-Martin
    >
    >
    >
    >--- In basicstamps@y..., "Henk Visser" <henk@h...> wrote:
    >>
    >> I am trying to take the output voltage from one pin and use that as
    >an input
    >> voltage for another pin. This is going to be used to determine the
    >level of
    >> water in a cup. Basically I need to get the value of pin1 to see
    >if it has
    >> been set high. If it has then I need to turn pin2 to high. From
    >the lines
    >> below I am not sure if I can do
    >>
    >> if pin1 = 1 then... ? Or is it looking for an actual voltage value
    >to
    >> compare it to?
    >>
    >>
    >> Thanks guys!
    >>
    >> ---- below is my code. Thank you very much! ----
    >>
    >>
    >> '{$stamp bs1}
    >>
    >
    > > output pin0 ' output voltage
    >> high pin0
    >>
    >> input pin1 ' waiting voltage.
    >>
    >> output pin2 ' toggle voltage.
    >> low pin2
    >>
    >>
    >>
    >> loop:
    >>
    >> if pin1 = 1 then pump_off ' Check to see if set high
    >> if pin1 < 1 then pump_on ' Check to see if set low
    > >
    > >
    > > pump_on:
    > > high pin2
    > > goto pump_on
    > >
    > > pump_off:
    > > low pin2
    > > goto pump_off
Sign In or Register to comment.