Hi Matthew,
Looking at the code you point to, a direct translation looks something like:
#include "mbed.h"
DigitalInOut pingPin(p5);
Timer t;
int main() {
pingPin.output();
wait_us(2);
pingPin = 1;
wait_us(5);
pingPin = 0;
pingPin.input();
// pulseIn
t.start();
while(!pingPin); // wait for high
int duration = t.read_us();
}
The function pulseIn just waits for the pin to go high, and returns the time, so I just used a timer.
You can't have two objects tied to the same digital pin at the same time, but you could dynamically create them (new/delete) to switch, or just wire up to two pins. Also, if you have some pseudo code of how you'd like it to work we could consider some API updates.
Simon
Has anyone made any attempt to get a PING from Parallax to work with an mbed? I just gave it a shot this evening and failed :-(
I have it working on my Arduino using the example code here: http://arduino.cc/en/Tutorial/Ping
I tried looking at the SRF05 example code, and I tried to use it as much as I could, however PING uses the same pin for trigger and echo. When I compiled my code I tried setting an InterruptIn on the same pin I was using for my DigitalOut trigger pin. Then I set functions to run on the rising and falling edges. However these interrupts never get called.
Any suggestions?
Matthew