Code source en BasicStamp BS2sx duSRF04 de Devantech

Forum sur la programmation Basic Stamp
Répondre
andromeda
Messages : 706
Enregistré le : 30 mars 2004 0:07
Contact :

Code source en BasicStamp BS2sx duSRF04 de Devantech

Message par andromeda » 05 mars 2007 11:27

Code : Tout sélectionner

'{$STAMP BS2sx}
'
' Devantech SRF04 Example
'

wDist var word
blips var nib

ECHO con 1
INIT con 0
'output 7


' CONVERSION FACTORS:
'
' The PULSIN command returns the round-trip echo time in 2us units
' which is equivalent to the one-way trip time in 1us units.
'
' distance = (echo time) / (conversion factor)
'
' use 74 for inches (73.746us per 1 in)
' use 29 for centimeters (29.033us per 1 cm)
'

convfac con 185 ' use inches

'---------------------------------------------

low 7

main
gosub sr_sonar_2
debug dec wDist, cr
pause 200
' if wDist < 5 then blink
goto main


sr_sonar:
for blips = 1 to 5
pulsout INIT,13 ' 10us init pulse
pulsin ECHO,1,wDist ' measure echo time
wDist = wDist/convfac ' convert to inches
pause 10
next
return

sr_sonar_2:
' for blips = 1 to 5
pulsout INIT,13 ' 10us init pulse
output INIT ' dummy command (delay)
rctime ECHO,1,wDist ' measure echo time
wDist=wDist/convfac ' convert to inches
pause 10
' next
return


'blink:
' high 7
' pause 250
' low 7
' return
Moderator - Forum

Répondre