How to use LDR as button

I have the Panda II and I know this is a simple question, but when trying to assign an Input port as the LDR button, the pin is not recognized. I tried using EINT0 and P210.

I just want the LED to be controlled by the button

Code is shown below

using System;
using System.Threading;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;


namespace FEZ_Panda_II_Application2
{
    public class Program
    {
        public static void Main()
        {
            OutputPort LED;
            InputPort Button;

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);

            Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.EINT0, false, Port.ResistorMode.PullUp);

            while (true)
            {
                LED.Write(Button.Read());
                Thread.Sleep(10);
            }
        }
    }
}

Does this work for you?

Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false, Port.ResistorMode.PullUp);

If this does not work, then you might not have defined your project as a Panda II application.

1 Like

Yes! Guess I was over thinking… : )