Shop OBEX P1 Docs P2 Docs Learn Events
Prop PING Code help needed. — Parallax Forums

Prop PING Code help needed.

NWCCTVNWCCTV Posts: 3,629
edited 2013-07-18 16:46 in Propeller 1
I was able to successfully link to this Object from within my IR/Servo program. However, one is using Parallax Serial Terminal and the other uses FullDuplexSerial. How can I modify the attached code to not use the FDS and just run with the results, no Debug needed? I have tried to remark out the Debug commands but then the LED's stop working correctly.
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  PING_Pin      = 15                                          ' I/O Pin For PING)))
  LED1          = 8                                          ' I/O PIN for LED 1
  LED2          = 9                                          ' I/O PIN for LED 2
  ON            = 1
  OFF           = 0                                          
  Distlimit     = 6                                          ' In inches
  
VAR
  long  range
OBJ
  Debug  : "FullDuplexSerial"
  ping   : "ping"
  
PUB Start
  dira[LED1..LED2]~~
  outa[LED1..LED2]~
  Debug.start(31,30,0,9600)
  waitcnt(clkfreq + cnt)
    
  repeat                                                ' Repeat Forever
    debug.str(string(1,"PING))) Demo ", 13, 13, "Inches = ", 13, "Centimeters = ", 13))
    debug.str(string(2,9,2))
    range := ping.Inches(PING_Pin)                      ' Get Range In Inches
    debug.dec(range)
    debug.tx(11)
    debug.str(string(2,14,3))
    range := ping.Millimeters(PING_Pin)                 ' Get Range In Millimeters
    debug.dec(range / 10)                               ' Print Whole Part
    debug.tx(".")                                       ' Print Decimal Point
    debug.dec(range // 10)                              ' Print Fractional Part
    debug.tx(11)
    range := ping.Inches(PING_Pin)                      ' Get Range In Inches
  
   if range < Distlimit                                 ' Comparing range to a set value of 6 inches
     outa[LED1] := ON                                      ' P1 is on              
     outa[LED2] := OFF                                     ' P2 is off
   elseif range > Distlimit                             ' If range is further than 6 inches
     outa[LED1] := OFF                                     ' P1 is off    
     outa[LED2] := ON                                      ' P2 is on

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-18 15:32
    Make sure the indenting is correct (I think the IF is off)).

    Comment the Debug. statements out and remember to take out the extra calls to ping.millimeters and ping.inches
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-07-18 16:02
    Thanks Mike. The IF statement was fine, the culprit was the last call to ping.millimeters. I appreciate the help as always.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-07-18 16:46
    I thought I had messed it up but it is working.
Sign In or Register to comment.