haunteddansion
01-19-2007, 03:09 AM
I was looking at the posted code (at the bottem) and I was wondering how I would go out interfacing the distance mesured with the motion of a servo? Thanks for the help!
' {$STAMP BS2}
'--------------------------------------------------------
' variable declarations
val05· VAR· Byte· ' value where reading is stored
i· VAR· Byte· ' count variable for loop
'--------------------------------------------------------
' constant declarations
cl· CON· 14· ' pin 14 is output (clock)
dt· CON· 15· ' pin 15 is the input (data)
'--------------------------------------------------------
' I/O pin setup for detector
INPUT dt··· ' make pin 15 the input
HIGH cl····· ' make pin 14 output and high
DEBUG "Start", CR· ' indicate beginning
FOR i = 1 TO 40
· GOSUB read05··· ' take reading
· DEBUG DEC val05, CR· ' display result
· PAUSE 100··· ' stall so display readable
NEXT
DEBUG "Finish", CR· ' indicate end
END····· ' stop Stamp when done
'--------------------------------------------------------
' subroutine read05
'
' This subroutine takes a reading from the connected
' GP2D05 detector and stores the value in "val05".
' Any two pins can be used.· Set "dt" to the data line
' of the GP2D05 (pin 3 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D05 (pin 1 on the
' JST connector, green wire).· Also, the IN15 needs
' to be set to the correct variable for the data pin
' (data line).
read05:
· LOW cl··· ' turn on detector for reading
· PAUSE 56··· ' wait 56ms for detector to read
· val05 = IN15··· ' obtain reading from detector
· HIGH cl··· ' turn off detector
· PAUSE 2··· ' wait for reset
RETURN
' {$STAMP BS2}
'--------------------------------------------------------
' variable declarations
val05· VAR· Byte· ' value where reading is stored
i· VAR· Byte· ' count variable for loop
'--------------------------------------------------------
' constant declarations
cl· CON· 14· ' pin 14 is output (clock)
dt· CON· 15· ' pin 15 is the input (data)
'--------------------------------------------------------
' I/O pin setup for detector
INPUT dt··· ' make pin 15 the input
HIGH cl····· ' make pin 14 output and high
DEBUG "Start", CR· ' indicate beginning
FOR i = 1 TO 40
· GOSUB read05··· ' take reading
· DEBUG DEC val05, CR· ' display result
· PAUSE 100··· ' stall so display readable
NEXT
DEBUG "Finish", CR· ' indicate end
END····· ' stop Stamp when done
'--------------------------------------------------------
' subroutine read05
'
' This subroutine takes a reading from the connected
' GP2D05 detector and stores the value in "val05".
' Any two pins can be used.· Set "dt" to the data line
' of the GP2D05 (pin 3 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D05 (pin 1 on the
' JST connector, green wire).· Also, the IN15 needs
' to be set to the correct variable for the data pin
' (data line).
read05:
· LOW cl··· ' turn on detector for reading
· PAUSE 56··· ' wait 56ms for detector to read
· val05 = IN15··· ' obtain reading from detector
· HIGH cl··· ' turn off detector
· PAUSE 2··· ' wait for reset
RETURN