MicroPython不仅能控制输出,还能读取各种传感器的数据。让我们来读取一个模拟传感器的值: from machine import ADC, Pinimport timeadc = ADC(Pin(34)) # 创建ADC对象,连接到GPIO 34while True: value = adc.read() # 读取模拟值 voltage = value /
value(0) p0.value(1) # create an input pin on pin #2, with a pull up resistor p2 = Pin(2, Pin.IN, Pin.PULL_UP) # read and print the pin value print(p2.value()) # reconfigure pin #0 in input mode with a pull down resistor p0.init(p0.IN, p0.PULL_DOWN) # configure...
先上代码: frommachineimportTouchPad,Pin#引入touchpad模块fromtimeimportsleepled=Pin(12,Pin.OUT)#在12脚外接一个led灯,也可利用板子自带ledtouch_pin=TouchPad(Pin(14))#定义14脚为触摸脚whileTrue:touch_value=touch_pin.read()print(touch_value)#打印出14脚感应的值iftouch_value>500:#若读取的值大于阀值...
from machine import Pin p2 = Pin(2, Pin.OUT) # create output pin on GPIO0 p2.on() # set pin to "on" (high) level p2.off() # set pin to "off" (low) level p2.value(1) # set pin to on/high p0 = Pin(0, Pin.IN) # create input pin on GPIO2 print(p0.value()) #...
# 关灯 >>> led.value(1) >>> led.on() # 开灯 >>> led.value(0) >>> led.off()记住,...
参见 pin.init()。类方法¶ classmethod Pin.debug([state])¶ 获取或设置调试状态(True 表示开启,False 表示关闭)。 classmethod Pin.dict([dict])¶ 获取或设置引脚映射字典。 classmethod Pin.mapper([fun])¶ 获取或设置引脚映射函数。方法¶ Pin.init(mode, pull=Pin.PULL_NONE, *, value=None,...
p0.value(1) # set pin to on/high p2 = Pin(2, Pin.IN) # create input pin on GPIO2 print(p2.value()) # get value, 0 or 1 p4 = Pin(4, Pin.IN, Pin.PULL_UP) # 使能内部上拉电阻p5 = Pin(5, Pin.OUT, value=1) # set pin high on creation ...
from machine import Pin p0 = Pin(0, Pin.OUT) # GPIO0设置为输出模式 p0.value(1) # p0输出高电平 p0.value(0) # p0输出低电平 p0.value() # 当前p0设置的电平 p2 = Pin(2, Pin.IN) # GPIO2设置为输入模式 p2.value() # p2的电平 ...
pin12.value(1) pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP) print(pin13.value()) i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22)) i2c.scan() i2c.writeto(addr, b'1234') i2c.readfrom(addr, 4) ...
Pin methods: init(..), value([v]), high(), low() pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object pyb.ADC(pin) -- make an analog object from a pin ADC methods: read(), read_timed(buf, freq)