Netduino in distant motion

Testing some alarm-related components (from left, motion sensor and distance sensor).

1-5865-13121870456662-IMG_8701

(Note the obligatory burn mark on the protective pad.)

To show how little code is involved, this is it (as far as a Q-n-D prototype goes).

Note that the distance sensor is non-linear. I haven’t added compensation for that yet. Note also that I intentionally don’t use a namespace. That’s to make the latter files project independent. The same code would apply to the original Netduino and Netduino Mini.

Program.cs

using System.Threading;
using Microsoft.SPOT;

public class Program
{
    public static void Main()
    {
        while (true)
        {
            LedStatus.status = ProtoBoard.motion;
            Debug.Print(“Motion: ” + ProtoBoard.motion + “, Distance: ” + ProtoBoard.distance);
            Thread.Sleep(1000);
        }
    }
}

LedStatus.cs

using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

class LedStatus
{
    private static OutputPort ledstatus = new OutputPort(Pins.ONBOARD_LED, false);

    public static bool status
    {
        set { set(value); }
    }

    public static void set(bool state)
    {
        ledstatus.Write(state);
    }
}

ProtoBoard.cs

using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;

class ProtoBoard
{
    private static InputPort pinMotion = new InputPort(Pins.GPIO_PIN_D11, true, Port.ResistorMode.PullUp);

    public static bool motion
    {
        get { return !pinMotion.Read(); }
    }

    private static AnalogInput pinDistance = new AnalogInput(Pins.GPIO_PIN_A0);

    public static int distance
    {
        get { return pinDistance.Read(); }
    }
}