我用Q4XTBLAF300-Q8配置了树莓派3这个传感器,它连接到GPIO5,用于读取基于传感器范围内的东西的值,输入将是高电平。当它超出范围时,传感器将是低电平。但是我不知道如何根据Q4XTBLAF300-Q8这个传感器状态来编写从GPIO5引脚读取值的代码。
那么,你能告诉我如何从Raspberry PI 3的GPIO5引脚读取值吗?
发布于 2017-09-25 15:50:04
下面是你可以参考的代码片段:
using Windows.Devices.Gpio;
private const int GPIO_PIN_NUM = 5;
//Initialize gpio
pin = GpioController.GetDefault().OpenPin(GPIO_PIN_NUM);
pin.SetDriveMode(GpioPinDriveMode.Input);
//Read gpio value
var pinValue = pin.Read();要想在带有Windows10IoT内核的树莓派上控制GPIO,你可以查看this tutorial。
更多示例是here。
发布于 2018-03-26 22:08:23
using Windows.Devices.Gpio;
public void GPIO()
{
// Get the default GPIO controller on the system
GpioController gpio = GpioController.GetDefault();
if (gpio == null)
return; // GPIO not available on this system
// Open GPIO 5
using (GpioPin pin = gpio.OpenPin(5))
{
// Latch HIGH value first. This ensures a default value when the pin is set as output
pin.Write(GpioPinValue.High);
// Set the IO direction as output
pin.SetDriveMode(GpioPinDriveMode.Output);
} // Close pin - will revert to its power-on state
}https://stackoverflow.com/questions/46397880
复制相似问题