import sys sys.path.append('../week7/rgb') from serial import Serial from strip import write_led_strip ser = Serial('COM6', 115200, timeout=1) while True: res = input() if 'r' == res: write_led_strip(ser, [[0.5, 0, 0]] * 8) if 'g' == res: write_led_strip(ser, [[0, 0.5, 0]] * 8) if 'b' == res: write_led_strip(ser, [[0, 0, 0.5]] * 8) ser.close()
# uniform random color at random interval # # Stanley H.I. Lio # [email protected] # OCN318, S18 import time from random import random from colorsys import hsv_to_rgb from serial import Serial from strip import write_led_strip DISP_LENGTH = 8 with Serial(input('PORT='), 115200, timeout=1) as ser: while True: try: c = hsv_to_rgb(random(), 1, 0.05) write_led_strip(ser, [c]*DISP_LENGTH) time.sleep(0.3*random()) except KeyboardInterrupt: break
return [hsv_to_rgb(h, saturation, brightness) for h in H] if '__main__' == __name__: DISP_LENGTH = 8 BRIGHTNESS = 0.05 SATURATION = 0.8 SPREAD = 0.8 STEP_DEGREE = 1 with Serial(input('PORT='), 115200*4, timeout=0.5) as s: deg = 0 while True: try: c = rainbow(DISP_LENGTH, shift=-deg/360., spread=SPREAD, saturation=SATURATION, brightness=BRIGHTNESS) write_led_strip(s, c) print('shift = {:5.1f} deg'.format(deg)) deg += STEP_DEGREE deg %= 360 #time.sleep(0.001) except KeyboardInterrupt: break
sys.path.append('../week7/rgb') from serial import Serial from strip import write_led_strip DISP_LENGTH = 8 with Serial(input('PORT='), 115200, timeout=1) as ser: while True: ser.write('read_raw_a0\n'.encode()) v = ser.readline() if len(v): v = float(v) / 1024.0 # normalize v from [0,1023] to [0,1] #print(v) count = int(v * 8) # map it to an integer in [0,8] print('囧' * count) try: tmp = [(0, 0, 0)] * DISP_LENGTH for i in range(count): tmp[i] = (v**3 * 0.3, 0, (1 - v) * 0.3) for i in range(count, DISP_LENGTH): tmp[i] = (0, 0, 0) write_led_strip(ser, tmp) #time.sleep(0.1) except KeyboardInterrupt: break
# set all pixels to cyan then exit # # Stanley H.I. Lio # [email protected] # OCN318, S18 from serial import Serial from strip import write_led_strip DISP_LENGTH = 8 with Serial(input('PORT='), 115200, timeout=1) as ser: color = [(0, 0.1, 0.07)] write_led_strip(ser, color * DISP_LENGTH) print('done.')