Cerbuino + PWM

Hello I want to test the first PWM example in GHI Electronics – Where Hardware Meets Software with Cerbuino
How can I assign the LED to the PWM channel?

Other than the reference to GHI.Premium.Hardware, the example would not really be changed much. You will use the GHI.OSHW.Hardware reference for the Cerbuino and [em]not[/em] the GHI.Premium.Hardware reference.

You will need to determine which output pin has the appropriate PWM Channel. For the Arduino-styled headers you can use this code to determine which pin has PWM to put your LED: FEZCerbuino.Pin.PWM.

For the Gadgeteer sockets you will need to reference the socket type P which has PWM Channels on pins 7, 8, and 9.


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHI.OSHW.Hardware;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            PWM MyFader = new PWM(FEZCerbuino.Pin.PWM.D0, 10000, 0.1, false);

            double i = 0.0;
            while (true)
            {
                MyFader.DutyCycle = i;
                /* DutyCycle is not dynamic so we must make a call to
                 * Start() to refresh the object */
                MyFader.Start();

                if ((i += 0.1) >= 1.0)
                {
                    i = 0.0;
                }

                Thread.Sleep(10);
            }
        }

    }
}

This code uses D0 on the Arduino-Style Headers. Make sure you are using the proper resistors with the LED before attaching to the board.

Thanks, that looks a bit nicer.
But I mean the LED of the board.

Unfortunately it is not possible to assign that particular LED to a PWM channel. It is attached to pin PB1. You can only blink this LED by assigning it to an OutputPort.