我有一个Windows IOT核心应用程序,它将输出写入GPIO引脚,我需要在三个引脚上设置可变电压,以将RGB灯设置为任何颜色。
问题是我只能将引脚设置为高值或低值,两者之间没有任何内容:
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);
}
如果有人能指出我正确的方向,能够在引脚上写一个介于1和0之间的值,我将不胜感激。
对于此版本的Core IOT,可能甚至不可能。
更新
感谢leppie的评论我现在意识到我当然需要使用PWM。
所以现在的问题是有人知道如何在Windows Core IOT上使用PWM吗?
答案 0 :(得分:1)
目前不支持PWM。我期待它在以后的版本中。在此期间,您可以将RPi2连接到Arduino。您可以访问Arduino上的PWM。请参阅this sample in the file ControlPage.xaml.cs。
Mark Radbourne [MSFT]
答案 1 :(得分:1)
我们在iot-devices project中添加了对软件PWM和硬件PWM的C#支持。您也可以使用Windows IoT Core和PWM咨询驱动步进电机的this C++ example。