from machine import Pin, I2C, ADC
import ssd1306
# ESP32 Pin assignment
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
joy_x = ADC(25)
joy_y = ADC(33)
sprite = [
[0,0,1,0,0],
[0,1,1,1,0],
[1,1,1,1,1],
[0,0,1,0,0],
[1,1,1,1,1]
]
while True:
oled.fill(0)
# Lees joystick waarden
val_x = joy_x.read_u16() # 0 .. 65535
val_y = joy_y.read_u16() # 0 .. 65535
# Schaal van 0–65535 naar schermbreedte/hoogte
# Houd rekening met sprite-grootte
pos_x = int((val_x / 65535) * (oled_width - len(sprite[0])))
pos_y = int((val_y / 65535) * (oled_height - len(sprite) - 6))
# Teken sprite
for y in range(len(sprite)):
for x in range(len(sprite[y])):
oled.pixel(pos_x + x, pos_y + y, sprite[y][x])
oled.text("x", pos_x - 1, pos_y + 7)
oled.show()