SRF04 as a backwarner
Robban
Posts: 124
Hi!
I wonder if anyone have tried to use the SRF04 as a backwarner.?
or if someone has tried to connect a ultrasonic sensor from a carsaler and then connected it to the stamp?
' {$STAMP BS2}
······ wDist· VAR· Word
INIT· CON· 0
ECHO· CON· 1
' 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· 29· ' use cm
'
main
· GOSUB sr_sonar
· DEBUG DEC wDist, CR
· PAUSE 200
· GOTO main
sr_sonar:
· PULSOUT INIT,5··· ' 10us init pulse
· PULSIN ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to cm
· PAUSE 10
· RETURN
sr_sonar_2:
· PULSOUT INIT,5··· ' 10us init pulse
· OUTPUT INIT··· ' dummy command (delay)
· RCTIME ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to cm
· PAUSE 10
· RETURN
i have tried the program "shown above" and it works pretty godd but sometimes the value(distance) is shown as "0"
ex
23
24
23
0
0
24
23
my question is WHY do i get the "zero:s"?
Post Edited (Robban) : 6/29/2006 6:31:12 PM GMT
I wonder if anyone have tried to use the SRF04 as a backwarner.?
or if someone has tried to connect a ultrasonic sensor from a carsaler and then connected it to the stamp?
' {$STAMP BS2}
······ wDist· VAR· Word
INIT· CON· 0
ECHO· CON· 1
' 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· 29· ' use cm
'
main
· GOSUB sr_sonar
· DEBUG DEC wDist, CR
· PAUSE 200
· GOTO main
sr_sonar:
· PULSOUT INIT,5··· ' 10us init pulse
· PULSIN ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to cm
· PAUSE 10
· RETURN
sr_sonar_2:
· PULSOUT INIT,5··· ' 10us init pulse
· OUTPUT INIT··· ' dummy command (delay)
· RCTIME ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to cm
· PAUSE 10
· RETURN
i have tried the program "shown above" and it works pretty godd but sometimes the value(distance) is shown as "0"
ex
23
24
23
0
0
24
23
my question is WHY do i get the "zero:s"?
Post Edited (Robban) : 6/29/2006 6:31:12 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com