Cobra II LDR1

Does anybody know how to use the LDR1 button in the code
how to declare?

If you were to use it in code, you can but be aware that this button has special properties upon both, powering up and resetting the board. It is used to put the device into Tinybooter or GHIbooter mode depending on the status of LDR0.

With that said, to add this into your program is relatively simple.

For either a Gadgeteer program or a regular console program you will want to add GHI.Hardware.G120 and Microsoft.SPOT.Hardware to your assemblies. At the top of the program code add the following using statements:

using Microsoft.SPOT.Hardware;
using GHI.Hardware.G120;

You will need to declare an InterruptPort or an InputPort with the pin as follows:

InterruptPort ldr1 = new InterruptPort(Pin.P0_22, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

In the body of the code you will need to set an event, if it is an interrupt port, or create a loop and poll the input pin after a small delay of say 250 ms.

Here is an example of setting an interrupt port:

ldr1.OnInterrupt += ldr1_OnInterrupt;

You will need to create a handler outside of the main program function for the interrupt example like so:

        void ldr1_OnInterrupt(uint data1, uint data2, DateTime time)
            lightLED = !lightLED;

Your code will vary.

Hope this helps.