--
Beat Döbeli Honegger - 03 Dec 2024
#set BLINKA_FT232H=1
import time
import usb
import usb.util
dev = usb.core.find(idVendor=0x0403, idProduct=0x6014)
#print(dev)
import board
#dir(board)
#import neopixel
import neopixel_spi as neopixel
import datetime
from PIL import ImageGrab
from PIL import Image
# Konfiguration der NeoPixel-LEDs
# 480x360
pixel_width = 140
pixel_height = 60
PIXEL_ORDER = neopixel.RGB
spi = board.SPI()
pixels = neopixel.NeoPixel_SPI(
spi,
pixel_width * pixel_height,
brightness=0.6 ,
pixel_order=PIXEL_ORDER,
auto_write=False,
)
pixels.fill((255, 0, 0))
pixels.show()
time.sleep(1)
pixels.fill((255, 255, 255))
pixels.show()
time.sleep(1)
#for x in range(pixel_width):
# pixels[0+x*pixel_height] = 0xFF0000
# pixels.show()
#pixel_framebuf.display()
# Initialisieren der NeoPixel-LEDs
#pixels = neopixel.NeoPixel(LED_PIN, LED_COUNT, brightness=LED_BRIGHTNESS, auto_write=False, pixel_order=LED_ORDER)
def rgb2hex(r,g,b):
return int('%02x%02x%02x' % (r, g, b), 16)
def capture_screen():
# Erfasse den gesamten Bildschirminhalt
screenshot = ImageGrab.grab(bbox=(1436,240,1908,450)) # 472 x 350 202
# Skaliere das Bild auf die Anzahl der LEDs, um die Farbinformationen zu extrahieren
scaled_image = screenshot.resize((pixel_width, pixel_height)) # 1 Zeile für LEDs
# Hole die Pixeldaten (RGB) des Bildes
pixel_data = scaled_image.load()
return pixel_data
def display_on_neopixel(pixel_data):
# Übertrage die Pixeldaten auf die NeoPixel-LEDs
# Setze den Farbwert auf die entsprechende NeoPixel-LED
t = ""
for y in range(pixel_height):
for x in range(pixel_width):
#r, g, b = pixel_data[x, y]
pixels[y+x*pixel_height] = pixel_data[x, y] #rgb2hex(r,g,b)
#t = t + " "+('#%02x%02x%02x' % (r, g, b))
#print(t)
pixels.show()
if __name__ == "__main__":
while True:
# Erfasse den Bildschirm und zeige es auf den NeoPixels an
pixel_data = capture_screen()
display_on_neopixel(pixel_data)
# Kurze Verzögerung, um nicht zu viele Updates zu senden
# time.sleep(0.01)