Peter Wessel
Published © Apache-2.0

Hello World nanoFramework on Electron

Hello World LEDs blinking using nanoFramework and UWP deploying to a very small IngenuityMicro Electron Board.

EasyProtip30 minutes225

Things used in this project

Hardware components

IngenuityMicro Electron
×1

Software apps and online services

nanoFramework Visual Studio extension
nanoFramework Visual Studio extension
nanoFramework GPIO Package

Hand tools and fabrication machines

Microsoft Visual Studio 2017 Preview 3

Story

Read more

Code

Blinking the LEDs on an IngenuityMicro Electron

C#
using System;
using System.Threading;
using System.Diagnostics;

using Windows.Devices.Gpio;

namespace pre3_Electron_1
{
    public class Program
    {
        #region GPIO
        // GPIO
        private const int GPIO_PIN_PA01 = 0 * 16 + 1;  // Led (Blue) for Electron
        private const int GPIO_PIN_PA08 = 0 * 16 + 8;  // Led (Green) for Electron
        private static GpioPin _ledBlue;
        private static GpioPin _ledGreen;
        private static GpioController _gpio;
        #endregion

        public static void Main()
        {
            // Necessary delay to give time
            Thread.Sleep(100);

            // You can remove this line once it outputs correctly on the console
            Console.WriteLine("Program started"); 

            try
            {
                // User code goes here
                
                // Get the GPIO controller
                _gpio = GpioController.GetDefault();
                
                // Initiate the LEDs
                _ledBlue = _gpio.OpenPin(GPIO_PIN_PA01);
                _ledBlue.SetDriveMode(GpioPinDriveMode.Output);
                _ledBlue.Write(GpioPinValue.Low);
                _ledGreen = _gpio.OpenPin(GPIO_PIN_PA08);
                _ledGreen.SetDriveMode(GpioPinDriveMode.Output);
                _ledGreen.Write(GpioPinValue.Low);

                // Do a infinitve loop of blinking the LEDs.
                for (; ; )
                {
                    _ledGreen.Write(GpioPinValue.High);
                    Thread.Sleep(50);
                    _ledGreen.Write(GpioPinValue.Low);
                    Thread.Sleep(50);
                    _ledGreen.Write(GpioPinValue.High);
                    Thread.Sleep(50);
                    _ledGreen.Write(GpioPinValue.Low);
                    Thread.Sleep(50);
                    _ledGreen.Write(GpioPinValue.High);
                    Thread.Sleep(50);
                    _ledGreen.Write(GpioPinValue.Low);
                    Thread.Sleep(250);

                    _ledBlue.Write(GpioPinValue.High);
                    Thread.Sleep(50);
                    _ledBlue.Write(GpioPinValue.Low);
                    Thread.Sleep(50);
                    _ledBlue.Write(GpioPinValue.High);
                    Thread.Sleep(50);
                    _ledBlue.Write(GpioPinValue.Low);
                    Thread.Sleep(50);
                    _ledBlue.Write(GpioPinValue.High);
                    Thread.Sleep(50);
                    _ledBlue.Write(GpioPinValue.Low);
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                // Do whatever please you with the exception caught
            }
            finally    // Enter the infinite loop in all cases
            {
                while (true)
                {
                    Thread.Sleep(200);
                }
            }
        }
    }
}

Credits

Peter Wessel

Peter Wessel

2 projects • 4 followers
Contributor for nanoFramework organisation, long time developer, started with a Motorola 6800 in machine code.
Contact

Comments

Add projectSign up / Login