56 lines
1.1 KiB
Python
56 lines
1.1 KiB
Python
import os.path
|
|
import serial
|
|
import time
|
|
import random
|
|
import logging
|
|
|
|
|
|
port_addr = '/dev/ttyACM0'
|
|
|
|
logging.warning("Staring up")
|
|
|
|
if os.path.exists(port_addr):
|
|
port = serial.Serial(
|
|
port=port_addr,
|
|
baudrate=115200,
|
|
bytesize=serial.EIGHTBITS,
|
|
parity=serial.PARITY_NONE,
|
|
stopbits=serial.STOPBITS_ONE,
|
|
timeout=1,
|
|
xonxoff=False,
|
|
rtscts=False,
|
|
dsrdtr=False,
|
|
write_timeout=None,
|
|
inter_byte_timeout=None)
|
|
|
|
logging.warning("Opening port")
|
|
|
|
time.sleep(2)
|
|
|
|
logging.warning("Opened port")
|
|
|
|
val1 = random.randint(0,100)
|
|
val2 = random.randint(0,100)
|
|
|
|
logging.warning("Staring with values %d and %d", val1, val2)
|
|
|
|
while True:
|
|
val1 += random.randint(-10,10)
|
|
val2 += random.randint(-10,10)
|
|
if val1 < 0:
|
|
val1 = 0
|
|
if val1 > 100:
|
|
val1 = 100
|
|
if val2 < 0:
|
|
val2 = 0
|
|
if val2 > 100:
|
|
val2 = 100
|
|
|
|
message = bytearray(3)
|
|
message[0] = 0xFF
|
|
message[1] = val1
|
|
message[2] = val2
|
|
|
|
port.write(message)
|
|
|
|
time.sleep(0.01)
|