Main Site Documentation

"button" not recognized


#1

I am truing run a project from here - http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx#comments using the button on the FEZ Cerberus board. I get the error that "The name ‘button’ does not exist in the current context ". Below is the code with the namespaces and attached the references. BTW - this is a problem I have all the time where I am not sure which namespaces and references should be included. Any idea?


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Hardware;
using System.IO.Ports;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace ButtonANDLight
{
            public partial class Program
    {
        GT.Timer ledBlinkTimer = new GT.Timer(1000);
 
        void ProgramStarted()
        {
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            ledBlinkTimer.Tick += new GT.Timer.TickEventHandler(ledBlinkTimer_Tick);
            ledBlinkTimer.Start();
           
        }
 
        void ledBlinkTimer_Tick(GT.Timer timer)
        {
            if (button.IsLedOn == true)
            {
                button.TurnLEDOff();
            }
 
            else
                button.TurnLEDOn();
        }
 
        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            Debug.Print("Button Pressed");   
        }
    }
}


#2

I have not since the button I was hoping to use is on the FEZ Cerberus board itself and not on a module. Did I get it wrong and I need the external/module button for this code?


#3

Got it thank you what about the green Led on the board? how do I address it?


#4
Mainboard.SetDebugLED(true);

#5

@ Gad - You can “turn” any pin to a button, by just connecting (touching) it to VCC or Ground (depending on what you want to be an active state) - that would be your button press. Then you can use plain netmf InterruptPort that will fire your “button” presses events or you can even use the button module class.