I connect my Digital Input to port 6, and the digital output to port 3, and I run the code:
And in the programmer I press F8, and I click "4800" you are supposed to see indents where your sonar sees an impediment, All I see is a series of "||(+)" it never gets bigger or smaller. And when I look at the SRF05 it does blink red, so it is getting power, what is the problem, is it the code?
Code:
Symbol servopin = 0' Defines output pin to which the servo turning the head is connected
symbol trig = 3 ' Defines output pin for Trigger pulse of SRF05
symbol echo = 6 ' Defines input pin for Echo pulse of SRF05
symbol servohead = 0 'Defines outnput pin for servo to turn SRF05
symbol range = w1 ‘ 16 bit word variable for range
symbol oldrange = w2' 16 bit word variable for "Where were we last time?"
symbol calcrange = w3 ' 16 bit word variable for "The difference"
symbol differencebit = 50 ' sets how little difference we can tolerate to call this "an object"
symbol kopbit = b25 ' this is overkill and not really used in here, but if you get my way of coding, you may see that it can be used for further investigation to have this variable ;)
main:
for b0 = 75 to 205 step 10
servo servohead, b0
pause 20
gosub puls
range = range / 3
if range > 150 then
range = 150
end if
for b1 = 1 to range
sertxd ("|")
next b1
'''
if oldrange > range then
calcrange = oldrange - range
if calcrange > differencebit then
kopbit = 1
end if
end if
'''
if oldrange < range then
calcrange = range - oldrange
if calcrange > differencebit then
kopbit = 2
end if
end if
'''
if kopbit = 0 then
sertxd ("(+)")
end if
kopbit = 0
sertxd (13, 10)
next b0
sertxd (13, 10)
servo servohead, 75
wait 1
goto main
''''''''''PULS''''''''''''
{
puls:
pause 10 ' this should not be nesecary, but it was of some reason in my setup
low 0 ' this should not be nesecary, but if not, strange things hapened
pause 10 'this should not be nesecary, but that is what makes it all fun
pulsout trig,1 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,range ‘ measures the range in 10uS steps
pause 10
return
}