[英]Check For Voltage With A Raspberry Pi 2b GPIO Pin
I want to build a simple (game)controller for my raspberry pi 2b. 我想为我的树莓派2b构建一个简单的(游戏)控制器。 My plan is to connect the 3.3 voltage output to a button and than to whatever GPIO pin. 我的计划是将3.3电压输出连接到按钮,而不是任何GPIO引脚。
Is it possible to check for voltage with the GPIO pin? 可以通过GPIO引脚检查电压吗? Or are there more smoother ways to build one (Analog to Digital)? 还是有更平滑的方法来构建一个(模拟到数字)?
Please respect that I am developing in Visual Studio 2015 C# and my RP-OS is Windows 10. 请注意,我正在Visual Studio 2015 C#中进行开发,我的RP-OS是Windows 10。
You can read the status of the pin (High/Low) or you can use interrupts to receive events when the status changes. 您可以读取引脚的状态(高/低),也可以在状态更改时使用中断来接收事件。
The button and LED project is the very first examples either on the Raspberry Pi site or Windows IoT site . 在Raspberry Pi站点或Windows IoT站点上,按钮和LED项目是第一个示例。 The PushButton sample for C# uses interrupts to detect status changes. C#的PushButton示例使用中断来检测状态更改。
The OS or language doesn't matter so much as the fact that you are using an RPi. 操作系统或语言与使用RPi无关紧要。 In order to work with a pin, you need to open it, set its mode and then, either retrieve its value periodically ,or listen to an interrupt. 为了使用引脚,您需要先将其打开,设置其模式,然后定期检索其值或侦听中断。
In the sample, the following steps are taken: 在示例中,执行以下步骤:
buttonPin = gpio.OpenPin(BUTTON_PIN);
打开按钮图钉: buttonPin = gpio.OpenPin(BUTTON_PIN);
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp)
; 将其设置为输入: buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp)
; buttonPin.ValueChanged += buttonPin_ValueChanged;
使用事件处理程序监听中断: buttonPin.ValueChanged += buttonPin_ValueChanged;
Generally speaking, you should work with both Raspbian and Windows IoT to understand how RPi behaves: 一般来说,您应该同时使用Raspbian和Windows IoT来了解RPi的行为:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.