2
votes

I have a windows IOT Core application which writes output to the GPIO pins and I need to have a variable voltage set on three pins to set an RGB lamp to any colour.

Problem is I can only set the pins to high value or low value, nothing in between:

private void SetupLeds()
{
    var gpio = GpioController.GetDefault();

    _redLED = gpio.OpenPin(18);
    _redLED.SetDriveMode(GpioPinDriveMode.Output);

    _greenLED = gpio.OpenPin(23);
    _greenLED.SetDriveMode(GpioPinDriveMode.Output);

    _blueLED = gpio.OpenPin(24);
    _blueLED.SetDriveMode(GpioPinDriveMode.Output);

}    

public void Yellow()
{
    _redLED.Write(GpioPinValue.High);
    _greenLED.Write(GpioPinValue.High);
    _blueLED.Write(GpioPinValue.Low);
}

public void Red()
{
    _redLED.Write(GpioPinValue.High);
    _greenLED.Write(GpioPinValue.Low);
    _blueLED.Write(GpioPinValue.Low);
}

If anyone can point me in the right direction to be able to write a value between 1 and 0 on the pin I would appreciate it.

Maybe its not even possible for this version of Core IOT.

UPDATE

Thanks to leppie's comment I now realise that of course I need to use PWM.

So the question now is anyone know how to use PWM on Windows Core IOT?

2
That is what a digital port does, 1's and 0's, on or off. For an LED you could use PWM, or if available, a DAC.leppie
Ahh of course {face palms} need to use PWM!!!Richard

2 Answers

1
votes

PWM is currently not supported. I am expecting it to be in later builds. In the meantime you could interface your RPi2 to an Arduino. You can access the PWM on the Arduino. See this sample in the file ControlPage.xaml.cs.

Mark Radbourne [MSFT]

1
votes

We have added C# support for Software PWM and Hardware PWM in the iot-devices project. You may also consult this C++ example of driving a stepper motor using Windows IoT Core and PWM.