Press Ctrl+C to clear and exit. """) mote = Mote() mote.configure_channel(1, 16, False) mote.configure_channel(2, 16, False) mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) h = 1 try: while True: for channel in range(1, 5): pixel_count = mote.get_pixel_count(channel) for pixel in range(pixel_count): hue = (h + ((channel - 1) * pixel_count * 5) + (pixel * 5)) % 360 r, g, b = [ int(c * 255) for c in hsv_to_rgb(hue / 360.0, 1.0, 1.0) ] mote.set_pixel(channel, pixel, r, g, b) mote.show() time.sleep(0.05) except KeyboardInterrupt: mote.clear() mote.show()
while True: r = requests.get('http://api.thingspeak.com/channels/1417/feed.json') j = r.json() f = j['feeds'][-8:] f = [element for index, element in enumerate(f) if index % 2 == 0] print(f) channel = 1 for col in f: col = col['field2'] ## Older versions of Python may need this line ##r, g, b = tuple(ord(c) for c in col[1:].lower().decode('hex')) r, g, b = tuple(c for c in bytes.fromhex(col[1:])) for pixel in range(mote1.get_pixel_count(channel)): mote1.set_pixel(channel, pixel, r, g, b) mote2.set_pixel(channel, pixel, r, g, b) channel += 1 mote1.show() mote2.show() time.sleep(5) except KeyboardInterrupt: mote1.clear() mote2.clear() mote1.show() mote2.show()
from mote import Mote mote = Mote() mote.configure_channel(1, 16, False) mote.configure_channel(2, 16, False) mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) # Load image in RGB format and get dimensions: print "Loading..." img = Image.open(filename).convert("RGB") pixels = img.load() width = img.size[0] height = img.size[1] print "%dx%d pixels" % img.size if (height > mote.get_pixel_count(1)): height = 15 # Calculate gamma correction table, makes mid-range colors look 'right': gamma = bytearray(256) for i in range(256): gamma[i] = int(pow(float(i) / 255.0, 2.7) * 255.0 + 0.5) print "Displaying..." try: while True: # Loop forever for x in range(width): # For each column of image... for y in range(height): # For each pixel in column... value = pixels[x, y] # Read pixel in image mote.set_pixel(
#calculate the count for each for idx in range(0,3): channels_colour_delta[channel - 1][idx] = (channels_colour[channel - 1][idx] - old_channels_colour[channel - 1][idx]) / float(transition_step) channel += 1 print(channels_colour_rgb) if old_channels_colour != channels_colour: # Do the transition for step in range(0, transition_step): for channel in range(1, 5): for idx in range(0,3): old_channels_colour[channel - 1][idx] += channels_colour_delta[channel - 1][idx] r,g,b = hsv_to_rgb(old_channels_colour[channel - 1][0], old_channels_colour[channel - 1][1], old_channels_colour[channel - 1][2]); for pixel in range(mote.get_pixel_count(channel)): mote.set_pixel(channel, pixel, int(r), int(g), int(b)) mote.show() time.sleep(transition_time / transition_step) for channel in range(0, 4): for idx in range(0,3): old_channels_colour[channel][idx] = channels_colour[channel][idx] time.sleep(5) except KeyboardInterrupt: mote.clear() mote.show() time.sleep(0.1)
num_pixels = 16 mote.configure_channel(1, num_pixels, False) mote.configure_channel(2, num_pixels, False) mote.configure_channel(3, num_pixels, False) mote.configure_channel(4, num_pixels, False) colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 255)] try: # Display solid colour for i in range(5): for step in range(4): for channel in range(4): for pixel in range(mote.get_pixel_count(channel + 1)): r, g, b = colors[channel] mote.set_pixel(channel + 1, pixel, r, g, b) mote.show() time.sleep(0.01) colors.append(colors.pop(0)) # Fade out pixels from their last state for step in range(170): for channel in range(4): for pixel in range(mote.get_pixel_count(channel + 1)): r, g, b = [ int(c * 0.99) for c in mote.get_pixel(channel + 1, pixel) ] mote.set_pixel(channel + 1, pixel, r, g, b)
print("""Rainbow Press Ctrl+C to clear and exit. """) mote = Mote() mote.configure_channel(1, 16, False) mote.configure_channel(2, 16, False) mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) h = 1 try: while True: for channel in range(1,5): pixel_count = mote.get_pixel_count(channel) for pixel in range(pixel_count): hue = (h + ((channel-1) * pixel_count * 5) + (pixel * 5)) % 360 r, g, b = [int(c * 255) for c in hsv_to_rgb(hue/360.0, 1.0, 1.0)] mote.set_pixel(channel, pixel, r, g, b) mote.show() time.sleep(0.05) except KeyboardInterrupt: mote.clear() mote.show()