IO拓展模块/IoExtension

此模块有5个IO口可用于输出电压,读取电压

输出电压

IoExtension.write(port, value)
设置port口输出value%的电压,100%为5V
参数:
  • port (int) –

    端口:3~5

    只有3~5端口可以输出电压
  • value (int) – 电压百分比:0~100

Examples

# 控制3~5端口的输出电压在0v~5v之间转换
from wonderbits import IoExtension
import time

ioExtension1 = IoExtension()

while True:
    ioExtension1.write(3,100)
    ioExtension1.write(4,100)
    ioExtension1.write(5,100)
    time.sleep(1)
    ioExtension1.write(3,0)
    ioExtension1.write(4,0)
    ioExtension1.write(5,0)
    time.sleep(1)

读取电压

IoExtension.read(port)
可以读取1~5端口的电压值
其中1,2端口的电压为百分比参数,100% 表示5v
3,4,5端口只能区分0v和5v,True表示5V,False表示0v
参数:port (int) – 端口:1~5
返回:
返回类型:float

Examples

# 在display1上显示1~5端口的值
from wonderbits import IoExtension, Display
import time

ioExtension1 = IoExtension()
display1 = Display()

while True:
    display1.print(1,1,ioExtension1.read(1))
    display1.print(1,8,ioExtension1.read(2))
    display1.print(2,1,ioExtension1.read(3))
    display1.print(2,7,ioExtension1.read(4))
    display1.print(2,13,ioExtension1.read(5))

事件源