Shop OBEX P1 Docs P2 Docs Learn Events
BS2p input syntax — Parallax Forums

BS2p input syntax

ArchiverArchiver Posts: 46,084
edited 2004-04-11 01:48 in General Discussion
Hello everyone,

I have several inputs to a BS2p that are either on or off and wanted
to declare the inputs like this:

remotealarm var bit
motiondetect var bit
doorsensor var bit

question is, what methods are available to assign those to input
pins P0, P1, P2 ?

Is: remotealarm Pin5 one of the ways?
then following that I would need a DIR5 0 since it is an
input.

also need an example of an output bit that has a variable name and a
dedicated Pin.

I have not found any related examples except ones that are too simple
and others that are more involved than I need.

thanks for your help
Bruce

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-04-10 18:20
    Use the PIN type function (you must declare $PBASIC 2.5 for this) and
    your coding will become easy because the compiler can tell if you want
    to use the declared pin as an input (look at the INS register bit) or an
    output (set the OUTS register bit).

    Like this:

    RemoteAlarm PIN 5
    MotionDetect PIN 6
    DoorSensor PIN 7

    IsON CON 1
    IsOFF CON 0

    So if you write this:

    IF (RemoteAlarm = IsON) THEN
    ' do something
    ENDIF

    It is the same as writing

    IF (IN5 = 1) THEN
    ' do something
    ENDIF

    By using the PIN declaration your code will be easier to read and debug,
    and you'll be able to adjust the circuit with one edit (PIN declaration
    line) versus all the places in your program that might examine that pin.

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office



    Original Message
    From: etech500 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=juOYbJ3OD_wChC2ujDxXQIjBGn0VC_Ck0WZlyy8t-_MEkmHlfDKTu8sndqcx1tIZM6rxujBBjqgraZQ]bmwbruce@a...[/url
    Sent: Saturday, April 10, 2004 1:09 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] BS2p input syntax


    Hello everyone,

    I have several inputs to a BS2p that are either on or off and wanted
    to declare the inputs like this:

    remotealarm var bit
    motiondetect var bit
    doorsensor var bit

    question is, what methods are available to assign those to input
    pins P0, P1, P2 ?

    Is: remotealarm Pin5 one of the ways?
    then following that I would need a DIR5 0 since it is an
    input.

    also need an example of an output bit that has a variable name and a
    dedicated Pin.

    I have not found any related examples except ones that are too simple
    and others that are more involved than I need.

    thanks for your help
    Bruce




    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.

    Yahoo! Groups Links







    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2004-04-10 22:18
    Hi Bruce,

    If you want further explanation of how the PIN typing works, the
    following URL may either resolve confusion (or add too it!)

    http://www.emesystems.com/BS2pbasic25.htm#PIN_examples

    Most of the time, the PIN type will do exactly what you want. But
    there are "tricky" uses where you need to understand the underlying
    actions.

    -- Tracy



    >Use the PIN type function (you must declare $PBASIC 2.5 for this) and
    >your coding will become easy because the compiler can tell if you want
    >to use the declared pin as an input (look at the INS register bit) or an
    >output (set the OUTS register bit).
    >
    >Like this:
    >
    >RemoteAlarm PIN 5
    >MotionDetect PIN 6
    >DoorSensor PIN 7
    >
    >IsON CON 1
    >IsOFF CON 0
    >
    >So if you write this:
    >
    > IF (RemoteAlarm = IsON) THEN
    > ' do something
    > ENDIF
    >
    >It is the same as writing
    >
    > IF (IN5 = 1) THEN
    > ' do something
    > ENDIF
    >
    >By using the PIN declaration your code will be easier to read and debug,
    >and you'll be able to adjust the circuit with one edit (PIN declaration
    >line) versus all the places in your program that might examine that pin.
    >
    >-- Jon Williams
    >-- Applications Engineer, Parallax
    >-- Dallas Office
    >
    >
    >
    >
    Original Message
    >From: etech500 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=xaP4TgyaLlF0DwRjWn7goUUwTrHsisYdYuDkOXpQ44ArBCWifcmVjyR_8aoHVYthH3U0rQ0wig]bmwbruce@a...[/url
    >Sent: Saturday, April 10, 2004 1:09 AM
    >To: basicstamps@yahoogroups.com
    >Subject: [noparse][[/noparse]basicstamps] BS2p input syntax
    >
    >
    >Hello everyone,
    >
    >I have several inputs to a BS2p that are either on or off and wanted
    >to declare the inputs like this:
    >
    >remotealarm var bit
    >motiondetect var bit
    >doorsensor var bit
    >
    > question is, what methods are available to assign those to input
    >pins P0, P1, P2 ?
    >
    >Is: remotealarm Pin5 one of the ways?
    > then following that I would need a DIR5 0 since it is an
    >input.
    >
    >also need an example of an output bit that has a variable name and a
    >dedicated Pin.
    >
    >I have not found any related examples except ones that are too simple
    >and others that are more involved than I need.
    >
    >thanks for your help
    >Bruce
    >
  • ArchiverArchiver Posts: 46,084
    edited 2004-04-11 01:48
    --- etech500 <bmwbruce@a...> wrote:
    > Hello everyone,
    > I have several inputs to a BS2p that are either on
    > or off and wanted
    > to declare the inputs like this:
    > remotealarm var bit
    > motiondetect var bit
    > doorsensor var bit

    Hey Bruce,

    Looks like you're building some sort of Alarm
    System. We've designed a few prototype Alarm Systems
    with the BS2, and are currently working on an advanced
    model using the BS2P40.

    > question is, what methods are available to assign
    > those to input
    > pins P0, P1, P2 ?
    >
    > Is: remotealarm Pin5 one of the ways?
    > then following that I would need a DIR5 0
    > since it is an
    > input.

    remotealarm pin 5

    This would work. As for the DIR5 0, well you can set
    up the DIRS for all pins with one command during the
    Initialization in your code. That's what I do.

    DIRS %1110001110001110 as an example.

    Hope this helps!


    =====
    Chris Savage
    Knight Designs
    324 West Main Street
    Montour Falls, NY 14865
    (607) 535-6777

    http://www.knightdesigns.com

    __________________________________
    Do you Yahoo!?
    Yahoo! Tax Center - File online by April 15th
    http://taxes.yahoo.com/filing.html
Sign In or Register to comment.