我在Rpi2上测试Win10 IoT,代码如下:
private void InitializeInterrupt()
{
GpioController gpioController = GpioController.GetDefault();
GpioPin buttonPin = gpioController.OpenPin(24);
_ledPin= gpioController.OpenPin(25);
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
_ledPin.Write(buttonPin.Read());
_ledPin.SetDriveMode(GpioPinDriveMode.Output);
buttonPin.ValueChanged += OnButtonChanged;
}
private void OnButtonChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
{
//I know the condition is inversed, I want the led UP when the button is not closed
_buttonFeedbackPin.Write(args.Edge != GpioPinEdge.RisingEdge ? GpioPinValue.High : GpioPinValue.Low);
}
问题是我的OnButtonChanged没有被调用。我基本上只是将GPIO按钮连接到地面(也测试到VCC)。
奇怪的是,如果我手动调用buttonPin.Read()
,我会在内部找到正确的GpioPinValue
,那么我可能做错了什么