def warp_speed_effect(): # go from back column to front column with all rows lit cmd = cmd_template.format(cmd_dict['all_on'], 15, 0, 3, '{}', '{}') for i in range(6, -1, -1): print(cmd.format(i, i + 1)) ser.write(cmd.format(i, i + 1).encode()) time.sleep(0.5) delay = 0.1 ser.write(all_off_cmd) ser.write(cmd.format(1, 5).encode()) time.sleep(delay) ser.write(all_off_cmd) ser.write(cmd.format(2, 4).encode()) time.sleep(delay) ser.write(all_off_cmd) ser.write(cmd_template.format(cmd_dict['all_on'], 15, 0, 2, 2, 4).encode()) time.sleep(delay) ser.write(all_off_cmd) ser.write(cmd_template.format(cmd_dict['all_on'], 15, 0, 2, 2, 3).encode()) time.sleep(delay) ser.write(all_off_cmd) ser.write(cmd_template.format(cmd_dict['all_on'], 15, 0, 1, 2, 3).encode()) time.sleep(delay) ser.write(all_off_cmd) ser.write(cmd_template.format(cmd_dict['all_on'], 15, 0, 0, 2, 2).encode()) time.sleep(delay) ser.write(all_off_cmd)
def select_start_end_coordinates(): start_grid = random.choice(start_choices) if 'right' in start_grid: end_grid = random.choice(start_choices[2:]) else: end_grid = random.choice(start_choices[:2]) r = random.choice(row_choices) c = random.choice(col_choices) start_cmd = cmd_template.format(cmd_dict[start_grid], '{}', r, r + 1, c, c) end_cmd = cmd_template.format(cmd_dict[end_grid], '{}', r, r + 1, c, c) return start_cmd, end_cmd
def ptb_to_pta(pt_a, pt_b, r, cmd): slp = weight_ratio / (pt_b - pt_a) start = time.time() # go from pt_b to pt_a for c in range(pt_b, pt_a - 1, -1): ser.write( cmd_template.format(cmd_dict[cmd], bght, r[0], r[1], c, c).encode()) time.sleep(slp) ser.write( cmd_template.format(cmd_dict[cmd], 0, r[0], r[1], c, c).encode()) print(time.time() - start)
def ship_takeoff(): # bottom right LED grid goes on (low to high rows/intensity) when blue lights go (3 seconds) # left LED grid goes (low to high row) brightness = 0 col = 1 print(cmd_template) tmp_cmd = cmd_template.format(cmd_dict['right_bottom_on'], '{}', '{}', '{}', col, col + 2) for i in range(3, -1, -1): brightness += 3 cmd = tmp_cmd.format(brightness, i, i + 1) print(cmd) ser.write(cmd.encode()) time.sleep(0.5) tmp_cmd = cmd_template.format(cmd_dict['right_top_on'], brightness, '{}', '{}', col, col + 2) for i in range(0, 4): cmd = tmp_cmd.format(i, i + 1) print(cmd) ser.write(cmd.encode()) time.sleep(0.5) ser.write(all_off_cmd) time.sleep(0.5) tmp_cmd = cmd_template.format(cmd_dict['left_bottom_on'], brightness, '{}', '{}', col, col + 2) for i in range(3, -1, -1): cmd = tmp_cmd.format(i, i + 1) print(cmd) ser.write(cmd.encode()) time.sleep(0.5) tmp_cmd = cmd_template.format(cmd_dict['left_top_on'], brightness, '{}', '{}', col, col + 2) for i in range(0, 4): cmd = tmp_cmd.format(i, i + 1) print(cmd) ser.write(cmd.encode()) time.sleep(0.5) ser.write(all_off_cmd)
def irritate_noise(): # for 0:23 - 0:25 cmd = cmd_template.format(cmd_dict['left_top_on'], 15, 2, 4, '{}', '{}') s = time.time() while time.time() - s < 2: ser.write(cmd.format(0, 1).encode()) time.sleep(0.2) ser.write(all_off_cmd) ser.write(cmd.format(1, 2).encode()) time.sleep(0.2) ser.write(all_off_cmd)
def r2d2_noise(): cmd = cmd_template.format(cmd_dict['right_bottom_on'], 15, 2, 3, '{}', '{}') s = time.time() while time.time() - s < 2: ser.write(cmd.format(0, 1).encode()) time.sleep(0.2) ser.write(all_off_cmd) ser.write(cmd.format(1, 2).encode()) time.sleep(0.2) ser.write(all_off_cmd)
def blink(r, c, cmd_type, seconds=0.5, tempo=0.1, note=note_dict['1/4'], rsl=False): cmd = cmd_template.format(cmd_type, led_brightness, r[0], r[1], c[0], c[1]) s = time.time() while time.time() - s < seconds: if rsl: ser.write(rsl_on_cmd.format(rsl_brightness).encode()) time.sleep(tempo) ser.write(cmd.encode()) if rsl: ser.write(rsl_off_cmd) time.sleep(note) ser.write(all_off_cmd)
# for _ in range(50): # c1 = random.randint(0, 4) # r11 = random.randint(0, 3) # r12 = r11 if random.random() >= 0.5 else r11 + 1 # c2 = random.randint(0, 3) # r21 = random.randint(0, 3) # r22 = r21 if random.random() < 0.5 else r21 + 1 # print(c1, r11, r12, c2, r21, r22) # p1 = Process(target=ptb_to_pta, args=(c1, c1+2, [r11, r12], 'top_on')) # p1.start() # p2 = Process(target=pta_to_ptb, args=(c2, c2+3, [r21, r22], 'bottom_on')) # p2.start() # p1.join() # p2.join() # time.sleep(rr) # ser.flush() # time.sleep(0.5) # ser.write(all_off_cmd) # ser.close() # time.sleep(5) start = time.time() # while time.time() - start < 1000: while True: time.sleep(rr) ser.write( cmd_template.format(cmd_dict['all_on'], bght, 0, 4, 0, 7).encode()) time.sleep(rr) ser.write(all_off_cmd) time.sleep(rr)
import random import serial import time from headset.shared import cmd_template, cmd_dict, all_off_cmd, rsl_on_cmd ser = serial.Serial('/dev/cu.SLAB_USBtoUART', 115200) ser.write(all_off_cmd) ser.write(rsl_on_cmd.format(250).encode()) bght=15 for _ in range(10): col = random.randint(0, 7) ser.write(cmd_template.format(cmd_dict['left_bottom_on'], bght, 0, 3, col, col).encode()) print(_, "got the stick!") time.sleep(random.uniform(0.5, 4)) ser.write(all_off_cmd) time.sleep(random.uniform(0.5, 2)) ser.write(all_off_cmd) ser.close()
r = 1 # for random column for _ in range(5): c = random.randint(0, 6) c2 = random.randint(0, 6) l_v_r = random.choice(['left', 'right']) l_v_r2 = random.choice(['left', 'right']) bot_cmd = '{}_bottom_on'.format(l_v_r) bot_cmd2 = '{}_bottom_on'.format(l_v_r2) top_cmd = '{}_top_on'.format(l_v_r) top_cmd2 = '{}_top_on'.format(l_v_r2) for b_r_s in range(3, -1, -1): print('\nb_r_s:', b_r_s) # turns on one LED ser.write( cmd_template.format(cmd_dict[bot_cmd], bght, b_r_s, b_r_s, c, c).encode()) ser.write( cmd_template.format(cmd_dict[bot_cmd2], bght, b_r_s, b_r_s, c2, c2).encode()) time.sleep(slp) tmp_b = bght for b_r_e in range(b_r_s + 1, 4): print('b_r_e:', b_r_e, tmp_b) tmp_b -= 1 ser.write( cmd_template.format(cmd_dict[bot_cmd], tmp_b, b_r_s, b_r_e, c, c).encode()) ser.write( cmd_template.format(cmd_dict[bot_cmd2], tmp_b, b_r_s, b_r_e, c2, c2).encode()) time.sleep(slp)
# ser = serial.Serial('/dev/cu.SLAB_USBtoUART', 115200) ser.write(all_off_cmd) bght = 10 slp = 0.01 start = 0 end = 20 cmd = 'left_top_on' # ser.write(rsl_on_cmd.format(200).encode()) while start != end: print(start, end) # light start column ser.write( cmd_template.format(cmd_dict[cmd], bght, 0, 3, start, start).encode()) time.sleep(slp) # go to end for c in range(start + 1, end): ser.write( cmd_template.format(cmd_dict[cmd], bght, 0, 0, c, c).encode()) time.sleep(slp) ser.write(cmd_template.format(cmd_dict[cmd], 0, 0, 0, c, c).encode()) # light end column ser.write( cmd_template.format(cmd_dict[cmd], bght, 0, 3, end, end).encode()) time.sleep(slp) # go back to start for c in range(end - 1, start, -1): ser.write( cmd_template.format(cmd_dict[cmd], bght, 0, 0, c, c).encode())
import time import random from headset.shared import cmd_template, cmd_dict, all_off_cmd, rsl_on_cmd ser = serial.Serial('/dev/cu.SLAB_USBtoUART', 115200) ser.write(all_off_cmd) bght = 10 start = time.time() ser.write(rsl_on_cmd.format(250).encode()) time.sleep(1) for _ in range(1): for r in range(4): for c in range(6): ser.write( cmd_template.format(cmd_dict['all_on'], bght, r, r, c, c).encode()) time.sleep(0.05) ser.write( cmd_template.format(cmd_dict['all_on'], bght, r + 1, r + 1, c + 1, c + 1).encode()) time.sleep(0.05) ser.write(all_off_cmd) time.sleep(0.25) for _ in range(1): for r in range(4): for c in range(6): ser.write( cmd_template.format(cmd_dict['all_on'], bght, r, r, c, c).encode()) time.sleep(0.05)