Step 3: Deploy your Application

The Meadow application template is a simple application that will pulse the onboard LED. As long as the Meadow.OS is deployed to your Meadow board, you can use the same techniques to deploy a Meadow application as you would any other .Net application:

macOS

Connect your Meadow device to your development machine

Press the Play button in Visual Studio to compile and deploy your application

Understanding the Hello, World App

The Meadow app template has two files; Program.cs and MeadowApp.cs, let’s take a quick look at them:

Program.cs

If you’ve created a .Net console app before, the Program class should look familiar; it’s very simple and only includes a static void Main() method that instantiates our Meadow app:

usingMeadow;usingSystem.Threading;namespaceHelloMeadow{classProgram{staticIAppapp;publicstaticvoidMain(string[]args){if(args.Length>0&&args[0]=="--exitOnDebug")return;// instantiate and run new meadow appapp=newMeadowApp();Thread.Sleep(Timeout.Infinite);}}}

This pattern allows us to have an App instance, in which all things Meadow are done.

Meadow Namespaces

These are the typical minimum set of namespaces in a Meadow app class and provide the following functionality:

Meadow - The root namespace contains Meadow application and OS classes, enabling you to interact with the Meadow.OS.

Meadow.Devices - Contains device-specific definitions for different Meadow boards, such as the F7 Micro Dev board, or the F7 Micro embeddable board.

Meadow.Foundation - Meadow.Foundation is a set of open-source peripheral drivers and hardware control libraries that make hardware development with Meadow, plug-and-play.

MeadowApp Class Definition

Notice that the HelloMeadow application class inherits from App, and has two generic arguments, in this case F7Micro, and HelloMeadow:

publicclassHelloMeadow:App<F7Micro,HelloMeadow>

All Meadow applications should inherit from the App base class. Under the hood, App registers itself with the Meadow.OS. It also provides hooks for getting notified during system events, such as the board being put to sleep.

App requires two parameters; first, the current device definition, and second, the type definition of your custom IApp class. These are passed to provide a strongly-typed reference to the current device, as well as the current instance of the application from anywhere in the app.

The device class defines properties and capabilities of the current device such as the pins, via the Device property on the App base class, and allows you to access them using autocomplete, via the specific device type:

Device.Pins.OnboardLedRed

publicMeadowApp(){Initialize();CycleColors(1000);}

This MeadowApp() call calls an initialization method, described below, and also a new method called CycleColors with a duration of 1000ms.

Controlling the Onboard LED via Ports

Direct access to hardware Input/Output (IO) is generally available via ports and buses. In this case, we create a IDigitalOutputPort for each color component (red, green, and blue) of the onboard LED:

The Initialize call writes to the console for informational purposes, useful when debugging and watching your app start. Then ports are created from the device itself, and the Pins property provides named pins that map to the pins available on the particular device specified above in the App definition.

Digital Output

To pulse the color of the light emitted via the onboard LED, we can utilize the built in StartPulse() method of the RgbPwmLed class, this is done in the ShowColorPulse method, which takes a color and duration. All of this is tied together with the CycleColors call which will simply cycle through a variety of colors: