ESP8266 LUA脚本语言开发: 外设篇-GPIO输入检测

咱使用 GPIO0

 

 https://nodemcu.readthedocs.io/en/master/modules/gpio/#gpioread

第一种

GPIO设置为输出的状态下读取引脚状态

gpio.mode(3, gpio.OUTPUT)
gpio.write(3, gpio.HIGH)

if  gpio.read(3) == 1 then
    print("GPIO0 is HIGH")
end

可以检测继电器输出的状态,自行扩展!

第二种

GPIO设置为输入的状态下.检测GPIO状态

gpio.mode(3, gpio.INPUT,gpio.PULLUP)

if  gpio.read(3) == 1 then
    print("GPIO0 INPUT is HIGH")
end

提示:

原文地址:https://www.cnblogs.com/yangfengwu/p/12037992.html