#! /usr/bin/env python from serial import serialposix as ser import time import math import random serport = ser.Serial ( port='/dev/ttyACM0', baudrate=115200 ) time.sleep ( 1 ) # wait for the Arduino bootloader to quit def linear ( val ): return max ( 0, min ( 127, int ( 127 * val**2 ) ) ) def picfunc ( pix, t ): return picfunc_xyz ( pix % 4, (pix / 4) % 4, (pix / 16) % 4, t ) def picfunc_xyz ( x, y, z, t ): return linear ( math.sin ( 2 * t + (x + y + z)/3. ) ** 2 ) t = 0.0 try: while True: time.sleep ( 0.01 ) t += 0.01 serport.write ( chr ( 255 ) + ''.join ( map ( chr, [linear ( random.random ( ) ** 256 ) for x in range ( 64 )] ) ) ) except KeyboardInterrupt: serport.write ( chr ( 255 ) + ''.join ( map ( chr, [0 for x in range ( 64 )] ) ) ) serport.close ( )