by i-Bot » Fri Sep 14, 2007 11:15 am
by i-Bot
Fri Sep 14, 2007 11:15 am
I tried your code and it worked for me,if rather slow.
I made a couple of changes, first because I put my POKE in an ugly place, and so you did too. Also results can be over 1000, so I added another digit.
The POKE is not needed really, since the motors had not been on since power up.
Results range from around 30 to 2500
SRF04 is a bit sensitive to local reflecting surfaces. I have foam around the sides of the transducers, and any close surfaces.
I have the SRF04 powered from the PWM2 pins. Servo 10 signal goes to middle hole in SRF04, Servo 11 signal to pin between middle and +5V. ERX is connected to a FTDI TTL to usb cable
DIM rr AS BYTE
DIM echo AS INTEGER
DIM thousands AS BYTE
DIM hundreds AS BYTE
DIM tens AS BYTE
DIM ones AS BYTE
POKE &H4ec,&hf3
loop:
echo = SONAR(5)
thousands = 48
hundreds=48
tens=48
ones=48
loop2:
IF echo>1000 THEN thousands=thousands+1
IF echo>1000 THEN echo=echo-1000
IF echo>1000 THEN GOTO loop2
IF echo>100 THEN hundreds=hundreds+1
IF echo>100 THEN echo=echo-100
IF echo>100 THEN GOTO loop2
IF echo>10 THEN tens=tens+1
IF echo>10 THEN echo=echo-10
IF echo>10 THEN GOTO loop2
IF echo>1 THEN ones=ones+1
IF echo>1 THEN echo=echo-1
IF echo>1 THEN GOTO loop2
ETX 9600,thousands
ETX 9600,hundreds
ETX 9600,tens
ETX 9600,ones
ETX 9600,13
ETX 9600,10
DELAY 100
GOTO loop
I tried your code and it worked for me,if rather slow.
I made a couple of changes, first because I put my POKE in an ugly place, and so you did too. Also results can be over 1000, so I added another digit.
The POKE is not needed really, since the motors had not been on since power up.
Results range from around 30 to 2500
SRF04 is a bit sensitive to local reflecting surfaces. I have foam around the sides of the transducers, and any close surfaces.
I have the SRF04 powered from the PWM2 pins. Servo 10 signal goes to middle hole in SRF04, Servo 11 signal to pin between middle and +5V. ERX is connected to a FTDI TTL to usb cable
DIM rr AS BYTE
DIM echo AS INTEGER
DIM thousands AS BYTE
DIM hundreds AS BYTE
DIM tens AS BYTE
DIM ones AS BYTE
POKE &H4ec,&hf3
loop:
echo = SONAR(5)
thousands = 48
hundreds=48
tens=48
ones=48
loop2:
IF echo>1000 THEN thousands=thousands+1
IF echo>1000 THEN echo=echo-1000
IF echo>1000 THEN GOTO loop2
IF echo>100 THEN hundreds=hundreds+1
IF echo>100 THEN echo=echo-100
IF echo>100 THEN GOTO loop2
IF echo>10 THEN tens=tens+1
IF echo>10 THEN echo=echo-10
IF echo>10 THEN GOTO loop2
IF echo>1 THEN ones=ones+1
IF echo>1 THEN echo=echo-1
IF echo>1 THEN GOTO loop2
ETX 9600,thousands
ETX 9600,hundreds
ETX 9600,tens
ETX 9600,ones
ETX 9600,13
ETX 9600,10
DELAY 100
GOTO loop