Sfr04 programming in C

c_for_pic18f4520.doc (25600Bytes)

Hi all,
I am programming an SFR04 sonar device using C. I have got a PICDEM2 plus starter kit from Microchip. com.
I am using an PIC18F chip that came with the board/kit. What I would like to do is use the L.E.D's on the kit to flash when an object is detected. I have a progamme but am having trouble incorperating the L.E.D's with it. I have put the programme on an attached file. Any pointers or help would be great.

Cheers

Pansonnic

You can’t actually "detect"
You can’t actually “detect” if there’s an object in front of your sonar, all you can do is figure out how far away something is. What I would recommend is you have the LED turned on briefly when the ping is returned, so that the closer an object is, the faster the LED will flash.

"In front of" is just a

"In front of" is just a matter of defining/deciding how close an object should be, before we say that it is in front of. Another way of defining “in front of” is mounting the distance sensor on a servo and scanning the front. If the distance measured at the far left and far right is greater than at the center, there might be some object in front of it.

 

I don’t know the PICDEM2. I am sure that there is some demo code that shows how to turn on/off the led. You just have to know, where to do it. At the bottom of the code, you have some “if (echo delay …” code. That is the point. Put something in front of it, use the debugger to find the value of echo_delay that should trigger the LED and use an

if (echo_delay > [value])
[turn on led];
else
[turn off led];

or something like that

Thanks for your replys. I

Thanks for your replys. I didnt realise that you cant detect an object. I think i will do what you said and get the L.E.D to flash quicker when the object gets closer.

Thanks