繁体   English   中英

如何使用C#从Raspberry PI 3的GPIO5引脚读取值?

[英]how to read value from GPIO5 pin of Raspberry PI 3 using C#?

我使用Q4XTBLAF300-Q8将此传感器配置为Raspberry PI 3,并将其连接到GPIO5以根据何时在传感器的范围内输入高将读取值。 超出范围时,传感器将变低。 但我不知道如何编写代码以根据Q4XTBLAF300-Q8此传感器状态从GPIO5引脚读取值。

那么,能否请您告诉我如何从Raspberry PI 3的GPIO5引脚读取值?

这是您可以参考的代码片段:

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();

要使用Windows 10 IoT核心版控制树莓派上的GPIO,可以查看本教程

更多样本在这里

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM