Shop OBEX P1 Docs P2 Docs Learn Events
How do scan inputs to monitor for a state change? — Parallax Forums

How do scan inputs to monitor for a state change?

samsn4samsn4 Posts: 49
edited 2008-08-29 00:38 in Propeller 1
I'm building an alarm and i want to scan the pins (about 10) for a state change, instead of a couple hundred if statements, is there a way to this more simplified? could i use a keypad object? (file attached). Next i need to store a number 0,1,2 and recall in later. ex.

pub start
check
if chk == 0
do this
if chk == 1
do this
if chk == 2
do this


pub check
this method checks all switches to be sure that they are in default state and not faulting, then returns a 0,1, or 2 depending on what is faulting


sorry if this is a bit muddy I'm a bit green and have only the basics down.

Thanks,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Daniel Mueth

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Just plug it in and let's see what happens"

Post Edited (samsn4) : 8/28/2008 6:28:06 PM GMT

Comments

  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-08-28 02:36
    Can you tell us more about your hardware? What are the pins connected to? Switches?

    One option may be using a CASE Statement and depending on what you are trying to do, another option may be using a Wait Unitl Pin Equal type of statement.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.

    www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
    www.sxmicro.com - a blog·exploring the SX micro
    www.tdswieter.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-08-28 02:46
    Please edit your message using the pencil icon top-right of the message and add a descriptive subject line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • samsn4samsn4 Posts: 49
    edited 2008-08-28 18:31
    What I'm building is an alarm for my motorcycle, I have two tilt switches for the main alarm trip and then vibration sensors in the saddle bag to monitor them. I also will be pulling a trailer and will extend the alarm to the trailer with a couple of plunger switches, as used for car doors. Thanks for help guys.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Daniel Mueth

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    "Just plug it in and let's see what happens"
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-08-28 19:43
    You best bet is to use waitpne or wait until pin(s) not equal, in the mask field you set the bits which correspond to the signals you are monitoring, and the state you set to the current state of those pins (with all pins not monitored set to 0). Whenever the state of any one of those pins changes, the instruction releases. You then check the value on the pins to determine which has changed and act accordingly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2008-08-29 00:38
    You may get some ideas from this project:

    Propeller Fire Alarm
    http://forums.parallax.com/showthread.php?p=738436

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Aka: CosmicBob
Sign In or Register to comment.