Toolbox.NETMF.Hardware.SharpGP2Y0A02YK


Toolbox.NETMF.Hardware.SharpGP2Y0A02YK(InputPort)
  • InputPort The analog port the sensor is connected to

Parameters

  • Distance The distance in centimeters

How to connect

Toolbox.NETMF.Hardware.SharpGP2Y0A02YK.png

Sample code in C#

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);
}

Sample code in VB

Dim Distance As SharpGP2Y0A02YK = New SharpGP2Y0A02YK(new Netduino.ADC(Pins.GPIO_PIN_A0))

Do
    Dim cm As Integer = Distance.Distance
    Dim inch As Integer = CInt(cm / 2.54)
    Debug.Print("Approximate distance: " + cm.ToString() + "cm / " + inch.ToString() + """")
    Thread.Sleep(1000)
Loop

Related documents

Last edited Jan 1, 2013 at 8:19 PM by Garrcomm, version 4