Shop OBEX P1 Docs P2 Docs Learn Events
Ultra Sonic Sensor need help coding to trigger event at specific distance. — Parallax Forums

Ultra Sonic Sensor need help coding to trigger event at specific distance.

JimLJimL Posts: 2
edited 2012-09-27 18:50 in Accessories
Hello all,

I am trying to figure out how to code the Basic Stamp to trigger a event when the US Sensor indicates the object is within a certain distance from the sensor. I think it is a "Do while" or "If" Statement but I am not a coder so if you could provide me with as much detail as you can without making it a special project for you I would greatly appreciate it. You can either post it here or send me a email jim@ly-core.com

I appreciate those who can assist in this.
Jim

Comments

  • ercoerco Posts: 20,255
    edited 2012-09-27 10:07
    In general:


    DO
    Measure distance (pulsout, pulsin)
    if distance<target then abc
    LOOP
    abc:
  • ercoerco Posts: 20,255
    edited 2012-09-27 17:44
    Or if you want 2 or 3 different actions:

    main:
    Measure distance (pulsout, pulsin)
    if distance>goalmax then abc' jump to label abc
    if distance<goalmin then efg' jump to label efg
    (code here executes if you create a hysteresis range goalmin<goalmax where your distance is OK as it)
    goto main
    abc:
    (code here executes if distance>goalmax)
    goto main
    efg:
    (code here executes if distance<goalmin)
    goto main
  • JimLJimL Posts: 2
    edited 2012-09-27 18:50
    erco wrote: »
    Or if you want 2 or 3 different actions:

    main:
    Measure distance (pulsout, pulsin)
    if distance>goalmax then abc' jump to label abc
    if distance<goalmin then efg' jump to label efg
    (code here executes if you create a hysteresis range goalmin<goalmax where your distance is OK as it)
    goto main
    abc:
    (code here executes if distance>goalmax)
    goto main
    efg:
    (code here executes if distance<goalmin)
    goto main

    Very kind of you, this will do the trick! I appreciate your time.
Sign In or Register to comment.