import smbus
import time
bus = smbus.SMBus(1)
DEVICE1 = 0x20 # Device address
IODIRA = 0x00 # Pin direction register
OLATA = 0x14 # Register for outputs
# Set all GPA pins as outputs
bus.write_byte_data(DEVICE1,IODIRA,0x00)
# Set output all 7 output bits to 0
bus.write_byte_data(DEVICE1,OLATA,0)
for num in range(0,5):
# Lights all on for 5 seconds
bus.write_byte_data(DEVICE1,OLATA,0b11111111)
time.sleep(1)
# Set all bits to zero
bus.write_byte_data(DEVICE1,OLATA,0)
我正在尝试使用PWM使DEVICE1(Adafruit MCP23017)输出引脚上的8个LED变暗。我正在使用smbus将二进制字符串写入芯片,该芯片会打开所有LED灯5秒钟。
我想知道如何使用PWM控制LED的亮度