#! /usr/bin/python import sys, lumitile, time, termios, select dev="/dev/ttyUSB0" if len(sys.argv) > 1: dev=sys.argv[1] kachel = lumitile.lumitile(port=dev, base=0) def getch(): """a simple nonblocking keyboard poll """ fd = sys.stdin.fileno() # do the input half of of tty.setraw() but keep ECHO and ICRNL, OPOST, etc mode = termios.tcgetattr(fd) # 0=IFLAG,1=OFLAG,2=CFLAG,3=LFLAG,4=ISPEED,5=OSPEED,6=CC mode[3] = mode[3] & ~termios.ICANON mode[6][termios.VMIN] = 1 mode[6][termios.VTIME] = 0 termios.tcsetattr(fd, termios.TCSADRAIN, mode) s = select.select([fd], [], [], 0) if len(s[0]): return sys.stdin.read(1) return 0 # for j in range(5): if 0: for i in range(256): kachel.send(i, 0, 0, delay=0.005) if (getch()): break for i in range(256): kachel.send(255-i, 0, 0, delay=0.005) if (getch()): break
#! /usr/bin/python import sys, lumitile dev = "/dev/ttyATH0" if len(sys.argv) > 1: dev = sys.argv[1] kachel = lumitile.lumitile(port=dev) def interpolate_rgb(idx, cols=[(255, 0, 0), (0, 0, 255)], steps=10, sigma=.5, dim=1.0): """sigma=0 is a linear interpolator, sigma=1 is a soft curve, sigma=10 is a stronger curve, holding the given colors longer, and transiting faster. (Low sigma's are almost always in transit, and show the given colors only briefly). """ top = steps * len(cols) idx = idx % top c1idx = int(idx / steps) c2idx = c1idx + 1 if (c2idx >= len(cols)): c2idx = 0 c1 = cols[c1idx] c2 = cols[c2idx] x = idx - c1idx * steps def pseudo_sin(x, sigma=0.5): """ takes an x in the range [0..1], a sigma value in the range [0..1] and returns a value in the range [0..1], with the following equations always true: pseudo_sin(0) == 0; pseudo_sin(0.5) == 0.5; pseudo_sin(1) == 1 the first derivative is 0 for x=0 and x=1. (except for sigma == 0, where
#! /usr/bin/python import sys, lumitile dev="/dev/ttyATH0" if len(sys.argv) > 1: dev=sys.argv[1] kachel = lumitile.lumitile(port=dev) def interpolate_rgb(idx, cols=[(255,0,0),(0,0,255)], steps=10, sigma=.5, dim=1.0): """sigma=0 is a linear interpolator, sigma=1 is a soft curve, sigma=10 is a stronger curve, holding the given colors longer, and transiting faster. (Low sigma's are almost always in transit, and show the given colors only briefly). """ top = steps * len(cols) idx = idx % top c1idx = int(idx / steps) c2idx = c1idx+1 if (c2idx >= len(cols)): c2idx = 0 c1 = cols[c1idx] c2 = cols[c2idx] x = idx - c1idx * steps def pseudo_sin(x, sigma=0.5): """ takes an x in the range [0..1], a sigma value in the range [0..1] and returns a value in the range [0..1], with the following equations always true: pseudo_sin(0) == 0; pseudo_sin(0.5) == 0.5; pseudo_sin(1) == 1 the first derivative is 0 for x=0 and x=1. (except for sigma == 0, where the derivative is always 1). The first derivative in x=0.5 is directly controlled by sigma. The curve is rotational symmetric around the point (0.5,0.5) """ if (sigma <= 0.000001): return x if (sigma > 1): sigma = 1
width = 10 height = 2 led_dev="/dev/ttyUSB0" vid_dev="/dev/video0" if len(sys.argv) > 1: led_dev = sys.argv[1] if len(sys.argv) > 2: vid_dev = sys.argv[2] if len(sys.argv) > 3: width = sys.argv[3] if len(sys.argv) > 4: height = sys.argv[4] if len(sys.argv) > 1 and (sys.argv[1] == '-h' or sys.argv[1] == '-?' or sys.argv[1] == '--help'): print "v4l2capture_dots.py V"+version print "\nUsage: %s [led_dev [video_dev [width [height]]]]" % sys.argv[0] print "\ndefaults:\n\tled_dev=%s\n\tvideo_dev=%s\n\twidth=%d\n\theight=%d" % (led_dev, vid_dev, width, height) # Open the LED_controller kachel = lumitile.lumitile(port=led_dev, base=1) # Open the video device. video = v4l2capture.Video_device(vid_dev) def image_to_dots(img, w=10, h=None, rows=2, pad=0, hflip=False, vflip=False): if h == None: # h = 3 * rows + 2 # we watch a third around the center. Two lines border minimum. h = int((2*pad+w)/4.*3.) strip=img.resize((w,h)) # strip.save("image.jpg") # print "Saved image.jpg (Size: " + str(size_x) + " x " + str(size_y) + ")" min_rgb = 255 max_rgb = 0 y = int((h-rows)/2)