

if (MoistureSensorOutputPin != null)
{
MoistureSensorOutputPin.SetDriveMode(GpioPinDriveMode.Input);
DispatcherTimer = new DispatcherTimer()
{
Interval = TimeSpan.FromSeconds(1)
};
DispatcherTimer.Tick += (O_O, n_n) =>
{
var pinValue = MoistureSensorOutputPin.Read();
if (pinValue == GpioPinValue.High)
{
Debug.WriteLine("Dry");
}
else
{
Debug.WriteLine("Water Detected!");
}
};
DispatcherTimer.Start();
}
}
注意不要用这个事件:
public event TypedEventHandler<gpiopin, gpiopinvaluechangedeventargs=""> ValueChanged;
这个会重复输出好多次的。。。
运行结果
传真:0755 - 2799 6625
投诉:133-2299-1235
邮箱:sale@inmiga.com