Hi aniMK16
The Sharp GP2Y0A02YK sensor outputs a voltage which you measure with an AnalogInput. This voltage can be converted into how far away the object is. (The NetMFToolbox driver code does the voltage to distance conversion)
From the netMF toolbox sample code
public static void Main()
{
SharpGP2Y0A02YK Distance = new SharpGP2Y0A02YK(new Netduino.ADC(Pins.GPIO_PIN_A0));
while (true)
{
int cm = Distance.Distance;
int inch = (int)(cm / 2.54);
Debug.Print("Approximate distance: " + cm.ToString() + "cm / " + inch.ToString() + "\"");
Thread.Sleep(1000);
}
}
The ultrasonic ranger I use in my blog post is a fairly common one. You initiate a measurement by strobing the trigger pin (with a digital output). Then measure the width of the pulse on the echo pin (with an InteruptPort triggering on both edges) which represents how far away the object is. My sample code in the event handler does the pulse width to distance conversion.
static void echoInterruptPort_OnInterrupt(uint data1, uint data2, DateTime time)
{
long pulseWidthTicks;
if (data2 == 1) // leading edge, start of pulse
{
pulseStartTicks = time.Ticks;
}
else
{
pulseWidthTicks = time.Ticks - pulseStartTicks;
long distance = pulseWidthTicks / 58;
Debug.Print("distance = " + distance.ToString() + "mm");
}
}
Based on the distance you could play different sound files using an MP3 player shield & code referred to in my previous post
@KiwiBryn
blog.devmobile.co.nz