Shop OBEX P1 Docs P2 Docs Learn Events
BS2 + Ping Sensor — Parallax Forums

BS2 + Ping Sensor

nick12nick12 Posts: 1
edited 2007-04-25 22:25 in BASIC Stamp
this is my first time posting here

I am using a bs2 and the parallax ping sensor with the example distance code but when the sensor does not detect an object the program will not continue to run. I was hoping that anybody could suggest how to get the bs2 to continue to run without it freezing when an object is not detected for a extended period of time. Attached below is the example code that I am using

' {$STAMP BS2}
' {$PBASIC 2.5}

time VAR Word

DO
PULSOUT 15,5
PULSIN 15, 1 , time
DEBUG HOME, "Time = ", DEC5 time
time = time ** 2251
DEBUG CR, "Distance = ", DEC4 time, "cm"
PAUSE 100

LOOP

Comments

  • PARPAR Posts: 285
    edited 2007-04-25 22:25
    nick12 said...
    this is my first time posting here

    I am using a bs2 and the parallax ping sensor with the example distance code but when the sensor does not detect an object the program will not continue to run. I was hoping that anybody could suggest how to get the bs2 to continue to run without it freezing when an object is not detected for a extended period of time. Attached below is the example code that I am using

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    time VAR Word

    DO
    PULSOUT 15,5
    PULSIN 15, 1 , time
    DEBUG HOME, "Time = ", DEC5 time
    time = time ** 2251
    DEBUG CR, "Distance = ", DEC4 time, "cm"
    PAUSE 100

    LOOP
    PULSIN will stop waiting for a return pulse after·a specified amount of time (that is determined by which Stamp you are using) and will return a zero value. So, it's not clear why your Stamp is "freezing". Do you have an object within a reasonable distance of the Ping when the system "freezes", or is the Ping indeed looking out into blank space?

    What is the evidence that the system is freezing? E.g., put a DEBUG statement before and after the DO, and another one after the PULSIN statements, to indicate that the program reached those statements. Do they all print?

    PAR
Sign In or Register to comment.