from machine import Pin, SoftI2C
import time
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
pcf8574_address = 0x20 # Beispieladresse, ändern Sie dies entsprechend Ihrer Verdrahtung
#i2c.writeto(PCF8575_ADDRESS, b'\xff') # Hier wird das Byte 0x00 an den PCF8575 geschrieben (--> alles an)
#data = i2c.readfrom(PCF8575_ADDRESS, 1) # Hier wird ein Byte von PCF8575 gelesen
# vorher müssen die Ports initialisiert werden i2c.writeto(PCF8575_ADDRESS, b'\xff')
# LED-Matrix Konfiguration (4x4)
rows = [0b00001111, 0b00001111, 0b00001111, 0b00001111] # Reihen P0-P3
cols = [0b11110000, 0b11110000, 0b11110000, 0b11110000] # Spalten P4-P7
def write_pcf8574(data):
i2c.writeto(pcf8574_address, bytearray([data]))
def clear_matrix():
write_pcf8574(0b11111111) # Alle LEDs aus
def set_led(row, col, state):
if state:
# LED einschalten
write_pcf8574(rows[row] & ~(1 << col))
else:
# LED ausschalten
write_pcf8574(rows[row] | (1 << col))
def light_pattern():
for i in range(4):
for j in range(4):
set_led(i, j, True)
time.sleep(0.1)
set_led(i, j, False)
while True:
#i2c.writeto(pcf8574_address, b'\x10') # Oben links P0 =0 P4=1 -> 10
#i2c.writeto(pcf8574_address, b'\xFE') # Obere Reihe links P0 =0 P1-3=1 P4-P7=1 -> FE
set_led(1,1,True)
#light_pattern()