ser = serial.Serial("/dev/ttyUSB0",9600,timeout=0.5)
try: #open serial #ser.open() #set BRIGHTNESS to 1 ser.write(str("WRITE_BRIGHTNESS=3\n").encode('UTF-8')) while(1): time.sleep(1) current_time = time.strftime("%H:%M:%S",time.localtime()) print("\r"+current_time,end='') ser.write(str(current_time+'\n').encode('UTF-8')) #close serial ser.close()
except Exception as e: print(e) ser.close() ```
### 2、显示英文 ``` import serial import serial.tools.list_ports
#open serial ser = serial.Serial("/dev/ttyUSB0",9600,timeout=10)
try: #set BRIGHTNESS to 3 ser.write(str("WRITE_BRIGHTNESS=3\n").encode('UTF-8')) #print hello on ledstick ser.write(str("hello \n").encode('UTF-8')) #close serial ser.close()
except Exception as e: ser.close() print(e) ```
### 3、显示随机数 ``` import serial import time import random
#open serial ser = serial.Serial("/dev/ttyUSB0",9600,timeout=0.5)
try:
#set BRIGHTNESS to 3 ser.write(str("WRITE_BRIGHTNESS=3\n").encode('UTF-8')) while(1): time.sleep(0.1) rand_num = random.randint(0,99999999) print("\r"+"%08d"%rand_num,end='') ser.write(str("%08d"%rand_num+'\n').encode('UTF-8')) #close serial ser.close()