Skip to content

Instantly share code, notes, and snippets.

@jaka
Created January 1, 2017 00:17
Show Gist options
  • Save jaka/db725ac8d1208f878f723d5a34de2cfb to your computer and use it in GitHub Desktop.
Save jaka/db725ac8d1208f878f723d5a34de2cfb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import serial
import random
from time import sleep
wait = 0.1
sp = serial.Serial(port='/dev/ttyACM0', baudrate=9600, timeout=2, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
def clean_buffer(sp):
if sp.inWaiting() > 0: sp.read(sp.inWaiting())
while True:
r = random.random()
if r > 0.9:
continue
else:
b = random.randint(1, 3) - 1
v = random.randint(1, 9)
u = [0, 0, 0]
u[b] = v
r = random.random()
if ( r > 0.8 ):
b = random.randint(1, 3) - 1
u[b] = v
str = b"%d%d%d." % tuple(u)
sp.write(str)
# sleep(wait)
# sp.write(b'.')
sleep(wait)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment