import serial, pygame, time port_ = 'COM7' # Hier ist ESP8266+ADXL345 angeschlossen baudrate_ = 9600 width = 800; height = 600 # Farbnamen definieren - RGB-Farbmodell red = (255,0,0); green = (0,255,0); blue = (0,0,255); yellow = (255,255,0) # Grafikfenster wird geöffnet screen = pygame.display.set_mode((width, height)) screen.fill(yellow) pygame.display.update() ser = serial.Serial(port_, baudrate_, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, timeout=1) ser.flushInput() txt = ser.readline().decode("UTF-8") # xo = width//2; yo = height//2 ende = False while not ende: txt = ser.readline().decode().rstrip() tmp = txt.split(",") if len(tmp)!=5: print(".", end="") continue #ADXL345b,68, 15, -20, 281 kennung = tmp[0] cnt = int(tmp[1]) ac_x = int(tmp[2]) ac_y = int(tmp[3]) ac_z = int(tmp[4]) print(ac_x, ac_y, ac_z) screen.fill(yellow) #dw = 50 #ac_x = (ac_x+dw//2)//dw*dw; ac_y = (ac_y+dw//2)//dw*dw pygame.draw.line(screen, blue, (xo,yo), (xo+ac_x, yo-ac_y), 5) pygame.display.update() # Bildschirm aktualisieren for event in pygame.event.get(): if event.type == pygame.QUIT: ende = True pygame.quit()