import os import serial import struct import time conn = serial.Serial("COM3" if os.name == "nt" else "/dev/ttyACM0") def change(channel, intensity): return struct.pack("B", (channel << 2) + intensity) try: print("Blinking (1sec intervals)... [Press ^C to exit]\x1b[?25l") while True: print("\r\x1b[32m- vibrating -\x1b[0m", end="", flush=True) conn.write(change(0, 1)) time.sleep(1) print("\r\x1b[35m- sleeping - \x1b[0m", end="", flush=True) conn.write(change(0, 0)) time.sleep(1) except KeyboardInterrupt: conn.write(change(0, 0)) print("\x1b[?25h")