# read_bpm.py import threading import serial bpm_value = 0 def read_serial(): global bpm_value ser = serial.Serial('COM9', 9600) while True: try: line = ser.readline().decode().strip() if line.isdigit(): bpm_value = int(line) except: continue t = threading.Thread(target=read_serial, daemon=True) t.start()