同一引脚可以用作输入/输出,程序控制的行为:
若没有上下拉电阻,无法读取引脚的高低电平的状态,因此它的作用即为确定引脚的状态
import utime, random
from machine import Pin, PWM
Red = Pin(16, machine.Pin.OUT)
Green = Pin(17, Pin.OUT)
ch = PWM(Pin(25)) # PWM at GP25
ch.freq(1000) # Frequency = 1000Hz
i = 0
while True:
ch.duty_u16(5000) # Change duty cycle
utime.sleep_ms(300) # Delay 300ms
r = random.randint(0, 1)
g = random.randint(0, 1)
Red.value(r)
utime.sleep(0.01)
Green.value(g)
utime.sleep(0.01)