FlexBASIC P2 PING
Rsadeika
Posts: 3,837
Does anybody have any P2 code for using the PING?
I looked in the Parallax github site for P2 objects, and nothing there. I did find some code for the P1, but the PASM part is way above my capabilities. I was thinking about trying to fit that code into a FlexBASIC Sub, but then I would not be able to share it with FlexC, if I ever needed to use FlexC.
Thanks
Ray
Comments
I have (cheap, chinese) ultrasonic distance detectors in my robot, but they have separate pins for echo and trigger and they are connected via inverters to a P2 and there are 8 of these in the robot.
It is doable in pure Basic as you have to make a pulse - the code makes 40 us pulse, I don't know what length and polarization is needed for PING:
Then you have to start a smart pin
Wait several miiiseconds letting the pin count the pulse length and after 10 miliiseconds or something like this, read the pin
This something is 1676 in my code to have the distance in milimeters at 285 MHz CPU speed. You have to compute this constant using sound speed, your CPU speed and length units.
us_trig and us_echo are the same in PING so you will need to stop the smartpin after the reading and before make the next pulse.
?? You can call FlexBASIC from FlexC, just the same as you can call Spin2 from FlexC. All of the Flex languages can work together.
I was watching the latest P2 early adopters youtube video, and I noticed that there is a P2 object for the PING. It is is located in the quick bytes area. The P2 objects are starting to get scattered, hopefully everything will start showing up in one place, again.
Ray
Here's how I read the Ping))) sensor with the P2 in my object. It's Spin2, so I will only post the method here for you to translate.
This should be easy to translate to FlexBASIC.