This project shows you how to run Meadow applications straight from a Windows machine using Meadow.Windows. You can even connect physical peripherals and/or sensors using an IO Expander like Adafruit's FT232H. As an example in this project, we'll wire up an RGB LED and control it using Meadow.Foundation
Meadow.Foundation a platform for quickly and easily building connected things using.NET on Meadow. Created by Wilderness Labs, it's completely open source and maintained by the Wilderness Labs community.
Step 1 - Assemble the circuitWire your project like this:
Create a new .NET Console application, and open the project file and replace it with the following:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Disclaimer: we currently don't have a Meadow.Windows template, so this the only way at this time to create Meadow applications that run on Windows.
Step 3 - Add the required NuGet packagesFor this project, search and install the following NuGet packages:
Step 4 - Add FT232H native library to your projectAdd the native library (libmpsse.dll) of the FT232H IO Expander depending on your CPU's architecture (Win32 or x64) to your project and set the Copy to Output Directory to Copy if newer
or Copy always.
Copy the following code below:
using Meadow;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Foundation.Leds;
public class MeadowApp : App<Windows>
{
RgbLed rgbLed;
public override Task Initialize()
{
Console.WriteLine("Creating Outputs");
var _expander = new Ft232h();
rgbLed = new RgbLed(
_expander.Pins.C2,
_expander.Pins.C1,
_expander.Pins.C0);
return Task.CompletedTask;
}
public override async Task Run()
{
while (true)
{
Resolver.Log.Info("Going through each color...");
for (int i = 0; i < (int)RgbLedColors.count; i++)
{
rgbLed.SetColor((RgbLedColors)i);
await Task.Delay(500);
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking through each color (on 500ms / off 500ms)...");
for (int i = 0; i < (int)RgbLedColors.count; i++)
{
await rgbLed.StartBlink((RgbLedColors)i);
await Task.Delay(3000);
await rgbLed.StopAnimation();
rgbLed.IsOn = false;
}
await Task.Delay(1000);
Resolver.Log.Info("Blinking through each color (on 1s / off 1s)...");
for (int i = 0; i < (int)RgbLedColors.count; i++)
{
await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
await Task.Delay(3000);
await rgbLed.StopAnimation();
rgbLed.IsOn = false;
}
await Task.Delay(1000);
}
}
public static async Task Main(string[] args)
{
await MeadowOS.Start(args);
}
}
Initialize
- Instantiate a FT232h object to use three digital output ports for the RGB LED, connected to pins C0, C1 and C2.Run
- At this point, the RGB LED object will be iterating over different colors and blinking animations inside an infinite while loop.Main
- For Meadow.Windows application, its important to add this Main task method that starts the MeadowOS runtime on Windows.
Click the Run button in Visual Studio. It should look like to the following GIF:
This project is only the tip of the iceberg in terms of the extensive exciting things you can do with Meadow.Foundation.
- It comes with a huge peripheral driver library with drivers for the most common sensors and peripherals.
- The peripheral drivers encapsulate the core logic and expose a simple, clean, modern API.
- This project is backed by a growing community that is constantly working on building cool connected things and are always excited to help new-comers and discuss new projects.
Comments