Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does raspberry pie control LED through RPIO?

Shulou Source: shulou.com Published: 2022-06-01 23:02:11 09月28日 Update

This article is about how raspberry pie controls LED through RPIO buttons. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.

1. Wiring diagram

2. Code: led.js

Const rpio = require ("/ home/pi/.nvm/versions/node/v10.15.3/lib/node_modules/rpio/lib/rpio")

Var pin = 32

Var pin1=37

Rpio.open (pin, rpio.OUTPUT, rpio.LOW)

Rpio.open (pin1, rpio.INPUT, rpio.PULL_DOWN)

Function flash (pin) {

For (var I = 0; I < 3; iTunes +) {

Rpio.write (pin, rpio.HIGH)

Rpio.sleep (1)

Rpio.write (pin, rpio.LOW)

Rpio.msleep (500)

}

}

Flash (pin)

/ / rpio.close (pin)

/ / rpio.close (pin1)

/ / Test button is pressed

Function buttonPressed () {

While (1) {

If (rpio.read (pin1) = = rpio.HIGH) {/ / low level detected

Rpio.msleep (20); / / Button Shake

If (rpio.read (pin1) = = rpio.HIGH) {

/ / rpio.write (pin, rpio.HIGH); / / illuminate LED

Flash (pin)

}

} else {

/ / rpio.write (pin, rpio.LOW); / / Button is off

}

}

}

ButtonPressed ()

3. Run:

Node led.js

This is how raspberry pie controls LED through RPIO buttons. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Buttons raspberries controls more knowledge articles testing utility code that is work meetings articles levels look knowledge points industry details information channels follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information vpn NVidia Docker