You aren't likely to get a response very quickly to a thread that has been inactive for several months. You are better off posting a new topic.
Also if you post source code use the code tags to make it display a little bit better.
How much experience do you have with C#? You problem is is the structure of the program. I ran this in the dedugger mode and you never get to where you expect which is calling calc().
Take a look at this compared to your code and see what the differences are.
using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace test { public class Ping { TristatePort cpuPort; public Ping(Cpu.Pin pin) { cpuPort = new TristatePort(pin, false, false, ResistorModes.Disabled); } public int distanceToTarget() { cpuPort.Active = true; // 1. Set CPU port to write mode cpuPort.Write(true); // 2. Send a pulse to the Ping))) sensor cpuPort.Write(false); cpuPort.Active = false; // 3. Put the port in read mode bool low = false; while (low == false) { low = cpuPort.Read(); } long tS = System.DateTime.Now.Ticks; // 4. Record start time when port goes high bool high = true; while (high == true) { high = cpuPort.Read(); } // 5. Listen for the return pulse long tE = System.DateTime.Now.Ticks; // 6. Record the time when the return pulse is recieved int t3 = (int)(tE - tS); return (t3) * 10 / 583; } } public class Program { public static void Main() { Ping ping = new Ping(Pins.GPIO_PIN_D2); while (true) { Debug.Print(ping.distanceToTarget().ToString()); Thread.Sleep(500); } } } }
Also how do you have your hardware wired?