print ' parsing layout file' print coordinates = [] for item in json.load(open(options.layout)): if 'point' in item: coordinates.append(tuple(item['point'])) #------------------------------------------------------------------------------- # connect to server print ' connecting to server at %s' % options.server print SOCK = opc_client.get_socket(options.server) #------------------------------------------------------------------------------- # color function def pixel_color(t, coord, ii, n_pixels): """Compute the color of a given pixel. t: time in seconds since the program started. ii: which pixel this is, starting at 0 coord: the (x, y, z) position of the pixel as a tuple Returns an (r, g, b) tuple in the range 0-255 """
print print ' Usage: raver_plaid.py [ip:port]' print print ' If not set, ip:port defauls to 127.0.0.1:7890' print sys.exit(0) #------------------------------------------------------------------------------- # connect to server print print ' connecting to server at %s' % IP_PORT print SOCK = opc_client.get_socket(IP_PORT) #------------------------------------------------------------------------------- # send pixels print ' sending pixels forever (control-c to exit)...' print n_pixels = 1250 # number of pixels in the included "wall" layout fps = 20 # frames per second # how many sine wave cycles are squeezed into our n_pixels # 24 happens to create nice diagonal stripes on the wall layout freq_r = 24 freq_g = 24
else: print print ' Usage: rgb_test_pattern.py [ip:port]' print print ' If not set, ip:port defauls to 127.0.0.1:7890' print sys.exit(0) #------------------------------------------------------------------------------- # connect to server print print ' connecting to server at %s' % IP_PORT print SOCK = opc_client.get_socket(IP_PORT) #------------------------------------------------------------------------------- # send pixels print ' sending pixels forever (control-c to exit)...' print n_pixels = 1250 # number of pixels in the included "wall" layout fps = 2 # frames per second (color switches every frame) while True: for c in range(4): pixels = [] rgb = [0, 0, 0] if c < 3:
led_count = 256 server = sys.argv[1] if len(sys.argv) > 1 else '127.0.0.1:7890' colors = { 128: (255,0,0), # red 64: (205, 140, 0), # orange 32: (255,255,0), # yellow 16: (0,255,0), # green 8: (0,0,255), # blue 4: (111, 0, 255), # "indigo" 2: (128, 0, 128), # purple 1: (255,255,255), # white } socket = opc_client.get_socket(server) while True: for x in reversed(range(8)): pixels = [(0,0,0)] * led_count bit = 2 ** x print(bit) color = colors[bit] for i in range(led_count): if i & bit: pixels[i] = color opc_client.put_pixels(socket, 0, pixels) time.sleep(3)
'--server', dest='server', default='127.0.0.1:7890', action='store', type='string', help='server IP and port') parser.add_option('-f', '--fps', dest='fps', default=1e9, action='store', type='int', help='frames per second') options, args = parser.parse_args() socket = opc_client.get_socket(options.server) black_white = [(0, 0, 0), (2, 2, 2)] rgb_bright = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] red_pixels = [(1, 0, 0)] * options.num_pixels green_pixels = [(0, 1, 0)] * options.num_pixels blue_pixels = [(0, 0, 1)] * options.num_pixels arrays = [red_pixels, green_pixels, blue_pixels] frame = 0 start_time, start_frame = time.time(), frame print 'First pixel will flash on and off every 10 frames.' print 'Second pixel will flash on and off every 100 frames.' print 'Third pixel will flash on and off every 1000 frames.' print print 'Testing %d pixels (Ctrl-C to quit)...' % options.num_pixels