Tutorial : writing a application

How to write an application using MBN drivers

For this tutorial, we will suppose that you have a BarGraph Click board and you want to code an application that is using it.
Furthermore it is assumed that you have completed all downloads and install on the First-time users page.

If it’s the fist time you’re using this board, then you may not have the corresponding driver. You should then go to the Downloads page and download it from the list of available drivers. The driver is zipped and contains complete commented out source code, an example application and a .chm help file.

Unzip this driver in a folder for future reference.

Open Visual Studio and create a new MicroFramework “Console application”.

 

Since the Bargraph driver is using PWM and SPI, you also have to add references to Microsoft.SPOT.Hardware and Microsoft.SPOT.Hardware.PWM :

You will of course need the MBN Core assembly, which is located in c:\Users\Public Documents\MBN (this was installed here by the setup program) :

 

Locate where you unzipped the BarGraph Click driver and “Add existing item” to your project :

 

Now, the solution should look like this :

 

So far, you have referenced the needed assemblies and added the driver’s source code to you project. So go to Program.cs source code. It should look like this :

You can remove the Debug.Print() statement as we don’t need it in our example.

At this stage, we need to add some Using statements :

 

Then declare our Bargraph object :

 

In the main() method, we will now add the initialisation sequence and working code :

The first line creates the Bargraph object, which will be plugged on Socket #1 on the mainboard. You can of course choose another socket if you have other Click boards.

It’s now almost done… The Bargraph is ready and only needs to be told how many leds it will light on 😉  Here, we tell it to display 6 bars with the 5 preceding leds being lit.

Should you want only the sixth led lit and not the others, simply use false as second parameter :

Last line is the standard way to terminate a NETMF program, telling it to sleep forever.

You’re done !

Now the complete source code should look like this :

Now you will have to tell Visual Studio that the deployment and debugging will be done on the MBN board. To do this, go in the Project properties, select the “.NET Micro Framework” tab and choose “Transport : USB”. Your MBN board should then appear in the device dropdown box below.

Screen Shot 071

This step needs to be done only once at the beginning of the debugging session.

You are now ready to : Compile and run !

If you want to add other Click boards, then you simply have to “Add existing item” to your project and select the corresponding driver’s source code. Yes, it’s that easy !

 

Tip :

If you want to easily use our drivers with modules connected on screw terminals, you may create a virtual MBN socket and use it in the driver constructor :

 

Tip

Once included, the MikroBusNet assembly will be available from the “Recent” tab in the references explorer.