Part 1 finished. How to do Part 2?

TEZARM

Senior Member
Ok I have done part 1 with the Ultrasonics Project. So far I have the following code which I am using from the SRF004 DATASHEET.

symbol trig = 3 ‘ Define output pin for Trigger pulse
symbol echo = 6 ‘ Define input pin for Echo pulse
symbol range = w0 ‘ 16 bit word variable for range




main:
pulsout trig,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin echo,1,range ‘ measures the range in 10uS steps
pause 10 ‘ recharge period after ranging completes
‘ now convert range to cm (divide by 5.8) or inches (divide by 14.8)
‘ as picaxe cannot use 5.8, multiply by 10 then divide by 58 instead
let range = range * 10 / 58 ‘ multiply by 10 then divide by 58
debug range ‘ display range via debug command
goto main ‘ and around forever

I want to display readout through leds not DEBUG Command. Lets start with 4 leds. I am using the picaxe 18a. How do I modify the program to do this for me? I don't even know where to start. Please help. I am bored of the DEBUG command already. I want to see some colour now and unplug the programming cable so I test this away from my pc. Can anyone help me with this. Oh and do I need the 10k pull up on my input when using the SRF004.
 

Fowkc

Senior Member
I couldn't find the SRF004 datasheet (only the SRF005), so I'm not sure about the pull-up 10K.

As for displaying the range, you should just be able to use a few IF statements, something like:

'Set all display pins to zero
'While preserving other outputs
pins = pins & %11110000

'Check range and jump accordingly
IF range > MaxValue THEN DispAll
IF range > ThreeQuarterValue THEN DispThree
IF range > HalfVal THEN DispTwo
IF range > QuarterVal THEN DispOne

'If code reaches here, you've practically 'crashed your car!
GOTO OtherRoutines

DispAll:
HIGH 3
DispThree:
HIGH 2
DispTwo:
HIGH 1
DispOne:
HIGH 0

GOTO OtherRoutines

I've assumed the use of output pins 0 to 3 for this. Direct LED connection will give the display then. Depending on the range to the object, the code will jump over the LEDs that don't need turning on.
 

TEZARM

Senior Member
Fowkc. You are simply BRILLANT. Thank you so much for helping me with my project. Great, another one to add to my Christmas Card list for 2006.
 

TEZARM

Senior Member
Hi Fowkc. I am confused. I cannot get that code figured out. It is me that is the problem. I should have posted for help with code but a 3 year old needs to understand it. Sorry. Stupid TEZARM.

My problems are:

symbol range = ?????????What

What values do I use for MaxValue etc.

What is Goto OTHER ROUTINES?

Maybe I misunderstood. Is the code you gave me to add into my existing code or standalone code by itself. Sorry for sounding like an idiot, but I am. I tried entering your code where the DEBUG command was but Program Editor is asking me What is That and What is This, Hang On you Stupid Program, I need to ask Fowkc first. Heeeeellllllllpppppp!!!!!!!
 

TEZARM

Senior Member
Oops. I just see Michael has sent me an email. Thanks Michael. Hang On a sec, I'll take a look now.
 

Rickharris

Senior Member
the following code operates a first try at a blind aid - The picaxe 08 produces 3 tones into a pizeo sounder on pin 2. 1. A tic to show everything is working, 2. a highe pitch warning when an object is within 1 meter, 3 a higher tone when the object is within 500 mm.

You can play with the variables to changes the tones as you wish.

symbol trig=1
symbol echo=3
symbol range=w1


start:

pulsout trig,2
pulsin echo,1,range
pause 10

let range=range*10/62



if range <50 then speed1
if range <90 then speed2
if range <110 then speed3

b4=5000
b6=10
gosub tick
goto start

speed1:
b4=10
b6=125
gosub tick
goto start

speed2:
b4=50
b6=100
gosub tick
goto start

speed3:
b4=2500
b6=30
gosub tick
goto start

tick:


for b5=1 to 3

sound 2,(b6,2)

pause b4
next b5
goto start


 

Fowkc

Senior Member
No need to apologise. I'm still bewildered by most of the code on the forum. That's what it's here for!

MaxValue will be the value above which you want all LEDs displayed. If you've got a value in centimeters, then just substitute, say 2 meters = 200 centimeters or whatever you need.

GOTO OtherRoutines was saying that the code I posted had finished, so you can replace "OtherRoutines" with wherever your particular code needs to go next. The first "OtherRoutines" (where I've put the bit about crashing) should really deal with extremely close ranges, as that's where the program will run to if the range is less then "QuarterVal".
 

TEZARM

Senior Member
Hi Rick and Fowkc.
I see what you mean Fowkc but I don't understand what the first "goto other routines" actually does. To get it to work I have to get rid of that first one. Anyway between your code and Ricks (Extremely confusing in some areas to me) code I have managed to get it to work. Basically I have stuck with your code Fowkc but I had to turn the '>' sign around the other way to '<'. It does seem to be working now but not when I unplug the programming cable. Have not figured out why it does this yet. Anyway thank you both very much for helping me out so far, you have both been a HUMUNGOUS help. I'll keep ya posted what happens next. Thanks to Michael 2727 aswell.
 
Top