GPIO — 控制I/O引脚

class GPIO(...)

使用示例::(python)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# coding=utf-8
# This is a sample Python script.
import utime
from driver import GPIO

print("start led test")
gpio = GPIO()
leds=("led1", "led2", "led3", "led4", "led5")
for i in range(5):
    for led in leds:
        gpio.open(led)
        gpio.write(1)
        utime.sleep_ms(200)
        gpio.write(0)
        utime.sleep_ms(200)
        gpio.write(1)
        utime.sleep_ms(200)
        gpio.close()

print("end led test")

配置信息::(json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding=utf-8
# This is a sample cjson file.
{
    "version": "1.0.0",
    "io": {
        "led1": {
            "type": "GPIO",
            "port": 34,
            "dir": "output",
            "pull": "pullup"
        },
        "led2": {
            "type": "GPIO",
            "port": 35,
            "dir": "output",
            "pull": "pullup"
        },
        "led3": {
            "type": "GPIO",
            "port": 36,
            "dir": "output",
            "pull": "pullup"
        },
        "led4": {
            "type": "GPIO",
            "port": 40,
            "dir": "output",
            "pull": "pullup"
        },
        "led5": {
            "type": "GPIO",
            "port": 41,
            "dir": "output",
            "pull": "pullup"
        }
    },
    "debugLevel": "DEBUG"
}

操作函数

open(jsonConfigPath, type)

打开并根据json文件配置GPIO实例

close()

关闭GPIO实例

read()

读取GPIO电平值,输入模式和输出模式时均可用

write(value)

设置GPIO电平值,GPIO引脚为输出模式时可用

toggle()

切换GPIO的电平,当前GPIO电平为低电平时设置为高电平,当前GPIO电平为高电平时设置为低电平