from machine import Pin, SPI
import ili9342c
#import axp202c
import random
#import vga2_16x32
#axp = axp202c.PMU(address=0x34)
#axp.enablePower(axp202c.AXP192_LDO2)
#axp.setDC3Voltage(3000)
spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))
tft = ili9342c.ILI9342C(spi, cs=Pin(5, Pin.OUT), dc=Pin(15, Pin.OUT), rst=Pin(33, Pin.OUT),width=320, height=240,rotation=270)
#tft = ili9342c.ILI9342C(spi, 320, 240, cs=Pin(5, Pin.OUT),dc=Pin(15, Pin.OUT), rotation=0)
#tft.fill(ili9342c.WHITE)
tft.clear(ili9342c.WHITE)
tft.text(font, "Hochschule",140,15,ili9342c.RED,ili9342c.WHITE)
# Anzahl Spalten und Zeilen
m = 6 # Spalten
n = 6 # Zeilen
# Berechnung der Rechteckgroessen
# (m+1) Abstaende horizontal, (n+1) Abstaende vertikal, je 10px
breite = (320 - (m + 1) * 10) // m
hoehe = (240 - (n + 1) * 10) // n
'''
for zeile in range(n):
for spalte in range(m):
x = 10 + spalte * (breite + 10)
y = 10 + zeile * (hoehe + 10)
# Zufaellige Farbe erzeugen
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
farbe = ili9342c.color565(r, g, b)
# Schwarzen Rand zeichnen (2px breit) = schwarzes Rechteck
tft.fill_rect(x, y, breite, hoehe, ili9342c.BLACK)
# Farbiges Rechteck 2px nach innen versetzt
tft.fill_rect(x + 2, y + 2, breite - 4, hoehe - 4, farbe)
'''