Saturday 26 January 2013

First Gadgeteer Program

I should have gone to bed, I was too excited to create my first Gadgeteer Program on the Argon R1 board ... here's the result :)

2 comments:

  1. Also it will be great & helpful if you try explain how you did that first simple led program from the beginning.

    ReplyDelete
  2. You'll first need to setup your computer with Visual Studio, .Net Micro Framework and Gadgeteer. Lots of info on the Gadget (and other websites) http://www.netmf.com/gadgeteer/

    That's OK, I've also put some links in an older post http://personal-drone.blogspot.co.uk/2013/01/pc-setting-up.html

    In terms of code, very simple :)

    On the Love Electronics Button Class there is an event handler called "ButtonPressed" (something like that as I'm not by my coding computer).

    The array of LEDs (ledArry) class has a method called LightLEDs(int) where you input the number of LEDs to light, put to a maximum of 7.

    Two minutes of code and something like this (from memory) will get you going :)

    // button and ledArray instance created in Gadget "wiring" diagram

    public partial class Program
    {
    // Maximum number of LEDs
    const uint MAX_LEDS = 7;

    // led count
    uint ledCount = 0;

    // This method is run when the mainboard is powered up or reset.
    void ProgramStarted()
    {
    // on start up make sure all leds are off
    ledArray.Clear();

    // add button_ButtonPressed event code to event handler
    button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);

    }

    void button_ButtonPressed(Button sender, Button.ButtonState state)
    {

    // calcualte the number of LEDs to count
    ledCount = ledCount < MAX_LEDS ? ++ledCount : 0;

    // this method lights up the LEDs :)
    ledArray.LightLeds(ledCount);

    return;
    }

    }

    ReplyDelete