def main(): try: mote = None try: 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) mote.clear() except: pass puzzled = Puzzled(mote) puzzled.start() if mote != None: for channel in range(1, 5): for pixel in range(16): mote.set_pixel(channel, pixel, 0, 0, 0) mote.show() curses.nocbreak() screen.keypad(False) curses.echo() curses.endwin() quit() except: curses.nocbreak() screen.keypad(False) curses.echo() curses.endwin() print(sys.exc_info())
def run(): """let's goooo""" 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) rand_cols = ColorRandom() patterns = [ pattern_floodfill, pattern_scatter, pattern_race, pattern_horizflood, pattern_horizsnakeflood, pattern_snakeflood, ] black = lambda: ColorConstant([0, 0, 0]) colors = [ ColorRandom, lambda: ColorConstant(rand_cols.get(None)), lambda: ColorChannelConstant(rand_cols), lambda: ColorChannelFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorGlobalFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorPixelFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorHorizCenterFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorRadialFade(rand_cols.get(None), rand_cols.get(None)), lambda: ColorChequerboard(rand_cols), ] last_col_template = None last_pattern_template = None while True: pattern_template = choice(patterns) if pattern_template == last_pattern_template: continue pattern = pattern_template() if random() < 0.5 else pattern_reverse( pattern_template()) color_template = black if (random() < 0.33 and last_col_template is not None) \ else choice(colors) if color_template == last_col_template: continue color = color_template() for update in pattern: c = color.get(update) prev_c = mote.get_pixel(update[0], update[1]) for step in range(8): step_c = lerp_cols(step / 7.0, prev_c, c) mote.set_pixel(update[0], update[1], step_c[0], step_c[1], step_c[2]) mote.show() time.sleep(0.03) last_col_template = color_template last_pattern_template = pattern_template
class MoteLamp(BaseLamp): def __init__(self, channels=4, correction=[1., 1., 1.]): self.mote = Mote() for c in range(channels): self.mote.configure_channel(c + 1, 16, False) BaseLamp.__init__(self, correction=correction) self.channels = channels self.pixels = 16 for channel in range(self.channels): self.mote.configure_channel(channel + 1, self.pixels, False) self.width = self.channels self.height = self.pixels # Clear all pixels def clear(self): self.mote.clear() self.mote.show() def show(self): self.mote.show() # Set a single pixel def set_pixel(self, x, y, r, g, b): r, g, b = self.apply_correction(r, g, b) self.mote.set_pixel(x + 1, y, r, g, b) # Set all pixels to RGB def set_all(self, r, g, b): self.color = (r, g, b) r, g, b = self.apply_correction(r, g, b) self.mote.set_all(r, g, b) # Set maximum global brightness def set_brightness(self, val): val = int(val) if 0 <= val <= 255: self.mote.set_brightness( val / 255) # Set brightness through unicornhat library self.brightness = val # Log user-selected brightness to a variable self.mote.show() else: logging.error("Brightness must be between 0 and 255")
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( 1, y, # Set pixel in strip gamma[value[0]], # Gamma-corrected red gamma[value[1]], # Gamma-corrected green gamma[value[2]]) # Gamma-corrected blue mote.show() # Refresh LED strip except KeyboardInterrupt: mote.clear() mote.show() quit()
from mote import Mote import time mote = Mote() mote.configure_channel(1, 16, False) while True: for pixel in range(16): mote.clear() mote.set_pixel(1, pixel, 0, 255, 0) mote.show() time.sleep(0.05) for pixel in range(15, -1, -1): mote.clear() mote.set_pixel(1, pixel, 0, 0, 255) mote.show() time.sleep(0.05)
mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) args.red = max(-1, min(args.red, 255)) args.green = max(-1, min(args.green, 255)) args.blue = max(-1, min(args.blue, 255)) args.max = max(1, min(args.max, 16)) try: while True: for channel in range(4): pixels = random.sample(range(16), random.randint(1, args.max)) for i in range(16): if i in pixels: mote.set_pixel( channel + 1, i, random.randint(0, 255) if args.red == -1 else args.red, random.randint(0, 255) if args.green == -1 else args.green, random.randint(0, 255) if args.blue == -1 else args.blue) else: mote.set_pixel(channel + 1, i, 0, 0, 0) mote.show() time.sleep(args.delay) except KeyboardInterrupt: mote.clear() mote.show() quit()
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()
print('power adapter') dongle = adapter.Adapter('/org/bluez/hci0') if not dongle.powered(): dongle.powered(True) print('discovery') dongle.nearby_discovery() ubit = device.Device( tools.device_dbus_path(constants.DEVICE_INTERFACE, 'puteg')[0]) while True: print('connect...') while not ubit.connected(): ubit.connect() while not ubit.services_resolved(): lights.set_pixel(1, 1, 255, 0, 0) sleep(0.1) lights.show() lights.clear() sleep(0.1) print('set up characteristics') ubit_btn_b = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'E95DDA90-251D-470A-A062-FA1922DFA9A8')[0]) ubit_btn_b.add_characteristic_cb(on_button_b) ubit_btn_b.start_notify() ubit_btn_a = Characteristic( tools.uuid_dbus_path(constants.GATT_CHRC_IFACE, 'E95DDA91-251D-470A-A062-FA1922DFA9A8')[0]) ubit_btn_a.add_characteristic_cb(on_button_a)
from mote import Mote import sys motes = Mote() motes.configure_channel(1, 16, False) r = int(sys.argv[1]) g = int(sys.argv[2]) b = int(sys.argv[3]) motes.clear() motes.set_pixel(1, 0, r, g, b) motes.set_pixel(1, 1, r, g, b) motes.set_pixel(1, 2, r, g, b) motes.set_pixel(1, 3, r, g, b) motes.set_pixel(1, 4, r, g, b) motes.set_pixel(1, 5, r, g, b) motes.set_pixel(1, 6, r, g, b) motes.set_pixel(1, 7, r, g, b) motes.set_pixel(1, 8, r, g, b) motes.set_pixel(1, 9, r, g, b) motes.set_pixel(1, 10, r, g, b) motes.set_pixel(1, 11, r, g, b) motes.set_pixel(1, 12, r, g, b) motes.set_pixel(1, 13, r, g, b) motes.set_pixel(1, 14, r, g, b) motes.set_pixel(1, 15, r, g, b) motes.show()
class MyApplication: def __init__(self): #1: Create a builder self.builder = builder = pygubu.Builder() self.doQuick = False self.timeSlices = 320 self.motePixelInSceenPixels = 1 self.graphWidth = self.timeSlices self.cameraLag = 3 self.currentColumn = 0 self.simulate = False self.animate = False self.completeRepeats = 0 self.motePixelInCm = 1 self.mode = MODE_IMAGE self.color = (255, 0, 0) self.colorend = (0, 0, 255) self.bCameraBusy = False self.bControlCamera = False self.bPaintFromLeft = True self.bFacingScreen = True self.bReverseImage = False self.bFlipVertical = False self.bGradient = False self.bPaintWhite = False self.bPaintBlack = False self.bTween = False self.bLines = False self.bSpeckles = False self.bRandomAcrossRange = False self.iDuration = 5 self.iRepeats = 1 self.iDelay = 0 screen_width = gtk.gdk.screen_width() screen_height = gtk.gdk.screen_height() #2: Load an ui file builder.add_from_file(os.path.join(CURRENT_DIR, 'main_repeats.ui')) self.motePixelInSceenPixels = 2 #3: Create the toplevel widget. self.mainwindow = builder.get_object('mainwindow') self.canPreview = builder.get_object('canPreview') self.msgMessage = builder.get_object('msgMessage') self.scaDelay = builder.get_object('scaDelay') self.scaDuration = builder.get_object('scaDuration') self.connectToMote() self.iPixels = len(self.yToStick) self.aColourGrid = [] self.aRandomGrid = [] self.updateControls() self.filename = "images/Spectrum Vertical.png" self.loadImage() self.makeRandom() builder.connect_callbacks(self) def beep(self, duration=0.1): freq = 440 # Hz os.system( 'play --no-show-progress --null --channels 1 synth %s sine %f' % (duration, freq)) def addStick(self, channel, up=True, length=16, gammacorrect=True): #from top if not self.simulate: self.mote.configure_channel(channel, length, gammacorrect) for i in range(length): if up: offset = length - 1 - i else: offset = i self.yToStick.append((channel, offset)) def connectToMote(self): self.showMessage("Connecting") try: from mote import Mote self.mote = Mote() self.simulate = False self.showMessage("Connected") if not self.simulate: self.mote.clear() self.mote.show() except IOError: self.simulate = True self.showMessage("Simulating") self.yToStick = [] self.addStick(1) self.addStick(2) self.addStick(3) self.addStick(4) def takePhoto2(self): self.bCameraBusy = True os.system(gphoto2_command) self.bCameraBusy = False return 0 def takePhoto(self): return self.takePhoto2() logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) self.bCameraBusy = True gp.check_result(gp.use_python_logging()) camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) print('Capturing image') file_path = gp.check_result( gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE)) print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name)) target = os.path.join('~/tmp', file_path.name) target = os.path.join(CURRENT_DIR, '..', 'LightPaintings', file_path.name) print('Copying image to', target) camera_file = gp.check_result( gp.gp_camera_file_get(camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)) gp.check_result(gp.gp_file_save(camera_file, target)) if (self.completeRepeats == self.iRepeats): subprocess.call(['xdg-open', target]) gp.check_result(gp.gp_camera_exit(camera)) self.bCameraBusy = False return 0 def quit(self, event=None): if not self.simulate: self.mote.clear() self.mote.show() self.mainwindow.quit() def reloadImage(self): self.mode = MODE_IMAGE self.loadImage() def loadImage(self): filename = self.filename self.im = Image.open(filename) iOriginalWidth, iOriginalHeight = self.im.size fAspect = float(iOriginalWidth) / float(iOriginalHeight) #targetWidth = int(fAspect * len(self.yToStick) * self.motePixelInCm) targetWidth = int(fAspect * self.iPixels * self.motePixelInCm) message = "Opened \"" + os.path.basename(filename) + "\" " + str( targetWidth) + "cm wide" self.showMessage(message) self.rgb_im = self.im.convert('RGB').resize( (self.timeSlices, self.iPixels), Image.NEAREST) self.width, self.height = self.rgb_im.size self.aImageValues = [[ self.rgb_im.getpixel((x, y)) for x in range(self.width) ] for y in range(self.height)] self.aRandomGrid = [[1 for x in range(self.width)] for y in range(self.height)] if (self.mode == MODE_IMAGE): self.drawPreview() def onFileChoose(self, event=None): self.filename = askopenfilename( initialdir="images/", title="Select file", filetypes=(("gif files", "*.gif"), ("png files", "*.png"), ("jpeg files", "*.jpg"), ("all files", "*.*"))) self.mode = MODE_IMAGE self.loadImage() def getColor(self, event=None): color = askcolor(self.color) if (color[0] == None): return if self.bPaintBlack == False: self.mode = MODE_COLOR self.color = color[0] self.drawPreview() def gradientChanged(self, event=None): self.mode = MODE_COLOR self.drawPreview() def getColorEnd(self, event=None): color = askcolor(self.colorend) if (color[0] == None): return self.bGradient = True self.updateControls() self.mode = MODE_COLOR self.colorend = color[0] self.drawPreview() def getImageX(self, processX): direction = (1 if self.bPaintFromLeft else -1) x = (0 if (direction == 1) else (self.timeSlices - 1)) + (direction * processX) return x def getPreviewX(self, processX): direction = (1 if self.bPaintFromLeft else -1) * (1 if self.bFacingScreen else -1) x = (0 if (direction == 1) else (self.timeSlices - 1)) + (direction * processX) return x def showColumn(self, x): iImageX = self.getImageX(x) if not self.simulate: try: for y in range(0, self.iPixels): try: if (self.bFlipVertical): colour = self.aPixels[(self.iPixels - y) - 1][iImageX] else: colour = self.aPixels[y][iImageX] except: colour = (0, 0, 0) channel, pixel = self.yToStick[y % len(self.yToStick)] if colour != (0, 0, 0): r, g, b = colour self.mote.set_pixel(channel, pixel, r, g, b) else: self.mote.set_pixel(channel, pixel, 0, 0, 0) self.mote.show() except IOError: self.simulate = True self.showMessage("Connection Failed. Simulating") def updateControls(self): self.builder.tkvariables.__getitem__('bGradient').set(self.bGradient) self.builder.tkvariables.__getitem__('bReverseImage').set( self.bReverseImage) self.builder.tkvariables.__getitem__('bFacingScreen').set( self.bFacingScreen) self.builder.tkvariables.__getitem__('bPaintFromLeft').set( self.bPaintFromLeft) self.builder.tkvariables.__getitem__('bPaintWhite').set( self.bPaintWhite) self.builder.tkvariables.__getitem__('iPixels').set(self.iPixels) self.builder.tkvariables.__getitem__('iDuration').set(self.iDuration) self.builder.tkvariables.__getitem__('iRepeats').set(self.iRepeats) self.builder.tkvariables.__getitem__('bControlCamera').set( self.bControlCamera) self.builder.tkvariables.__getitem__('bPaintBlack').set( self.bPaintBlack) self.builder.tkvariables.__getitem__('bTween').set(self.bTween) self.builder.tkvariables.__getitem__('bLines').set(self.bLines) self.builder.tkvariables.__getitem__('bSpeckles').set(self.bSpeckles) self.builder.tkvariables.__getitem__('bRandomAcrossRange').set( self.bRandomAcrossRange) self.builder.tkvariables.__getitem__('bFlipVertical').set( self.bFlipVertical) self.scaDelay.set(self.iDelay) def updateParams(self): self.bGradient = self.builder.tkvariables.__getitem__( 'bGradient').get() self.bReverseImage = self.builder.tkvariables.__getitem__( 'bReverseImage').get() self.bFacingScreen = self.builder.tkvariables.__getitem__( 'bFacingScreen').get() self.bPaintFromLeft = self.builder.tkvariables.__getitem__( 'bPaintFromLeft').get() self.bPaintWhite = self.builder.tkvariables.__getitem__( 'bPaintWhite').get() self.iPixels = self.builder.tkvariables.__getitem__('iPixels').get() self.iDuration = self.builder.tkvariables.__getitem__( 'iDuration').get() self.iRepeats = self.builder.tkvariables.__getitem__('iRepeats').get() self.bControlCamera = self.builder.tkvariables.__getitem__( 'bControlCamera').get() self.bPaintBlack = self.builder.tkvariables.__getitem__( 'bPaintBlack').get() self.bTween = self.builder.tkvariables.__getitem__('bTween').get() self.bLines = self.builder.tkvariables.__getitem__('bLines').get() self.bSpeckles = self.builder.tkvariables.__getitem__( 'bSpeckles').get() self.bRandomAcrossRange = self.builder.tkvariables.__getitem__( 'bRandomAcrossRange').get() self.bFlipVertical = self.builder.tkvariables.__getitem__( 'bFlipVertical').get() self.iDelay = self.scaDelay.get() def getColColour(self, px): if (self.bGradient): r = int( round(self.color[0] + float(self.colorend[0] - self.color[0]) * (float(px) / float(self.graphWidth)))) g = int( round(self.color[1] + float(self.colorend[1] - self.color[1]) * (float(px) / float(self.graphWidth)))) b = int( round(self.color[2] + float(self.colorend[2] - self.color[2]) * (float(px) / float(self.graphWidth)))) return (r, g, b) return self.color def getFrameColour(self): if (self.iRepeats > 1): j = self.completeRepeats r = int( round(self.color[0] + float(self.colorend[0] - self.color[0]) * (float(j) / float(self.iRepeats - 1)))) g = int( round(self.color[1] + float(self.colorend[1] - self.color[1]) * (float(j) / float(self.iRepeats - 1)))) b = int( round(self.color[2] + float(self.colorend[2] - self.color[2]) * (float(j) / float(self.iRepeats - 1)))) return (r, g, b) return self.color def transformThroughRandom(self, color, x, y, base=(0, 0, 0)): try: fMultiply = self.aRandomGrid[y][x] except: fMultiply == False if (fMultiply == False): return (0, 0, 0) else: return (int(round(fMultiply * float(color[0] - base[0]))) + base[0], int(round(fMultiply * float(color[1] - base[1]))) + base[1], int(round(fMultiply * float(color[2] - base[2]))) + base[2]) def dontPaintWhite(self, colour): if colour == (255, 255, 255): return (0, 0, 0) return colour def makeInvertedPixel( self, color, x, y, ): if color == (0, 0, 0): return self.aColorPixels[y][x] else: return (0, 0, 0) def makePixels(self): if self.bTween: self.aColorPixels = [[ self.getFrameColour() for x in range(self.width) ] for y in range(self.height)] else: if self.bRandomAcrossRange: self.aColorPixels = [[ self.transformThroughRandom(self.colorend, x, y, self.color) for x in range(self.width) ] for y in range(self.height)] else: self.aColorPixels = [[ self.getColColour(x) for x in range(self.width) ] for y in range(self.height)] if (self.mode == MODE_IMAGE): if self.bPaintBlack: self.aPixels = [[ self.makeInvertedPixel(self.aImageValues[y][x], x, y) for x in range(self.width) ] for y in range(self.height)] else: self.aRawPixels = self.aImageValues else: self.aRawPixels = self.aColorPixels if self.bPaintBlack == False: self.aPixels = [[ self.transformThroughRandom(self.aRawPixels[y][x], x, y) for x in range(self.width) ] for y in range(self.height)] if self.bPaintWhite == False: self.aPixels = [[ self.dontPaintWhite(self.aPixels[y][x]) for x in range(self.width) ] for y in range(self.height)] if self.bReverseImage == True: try: self.aPixels = [[ self.aPixels[y][(self.width - x) - 1] for x in range(self.width) ] for y in range(self.height)] except: print("failing", len(self.aPixels), self.width, x) def drawColumn(self, x): iImageX = self.getImageX(x) iPreviewX = self.getPreviewX(x) iPreviewXend = self.getPreviewX(x + 1) for y in range(0, self.iPixels): try: colour = self.aPixels[y][iImageX] except: colour = (0, 0, 0) if colour != (0, 0, 0): color = str(webcolors.rgb_to_hex(colour)) self.canPreview.create_rectangle( iPreviewX, (y * self.motePixelInSceenPixels), iPreviewXend, (y * self.motePixelInSceenPixels) + self.motePixelInSceenPixels, width=0, fill=color) if self.bPaintBlack & (self.currentColumn > 0 and self.currentColumn < self.graphWidth): self.canPreview.create_rectangle(iPreviewX, (0), iPreviewXend, self.motePixelInSceenPixels * 5, width=0, fill="#0F0") def doPreview(self, event=None): self.drawPreview() def changeRandom(self): self.updateParams() self.makeRandom() self.makePixels() self.drawPreview() def drawPreview(self): self.updateParams() self.makePixels() self.canPreview.create_rectangle( 0, 0, self.graphWidth, (len(self.yToStick) * self.motePixelInSceenPixels), fill="black") for x in range(0, self.graphWidth): self.drawColumn(x) def makeRandom(self): self.aRandomGrid = [[False for x in range(self.width)] for y in range(self.height)] for y in range(self.iPixels): if (self.bLines): line = [ random.randint(0, self.timeSlices), random.randint(0, self.timeSlices) ] line.sort() start = line[0] end = line[1] else: start = 0 end = self.timeSlices for x in range(0, self.timeSlices): if (x >= start and x <= end): if (self.bSpeckles or self.bRandomAcrossRange): level = random.random() else: level = 1 self.aRandomGrid[y][x] = level def refreshPixels(self): self.aImageValues = [[ self.rgb_im.getpixel((x, y)) for x in range(self.width) ] for y in range(self.height)] self.makePixels() def onShowEnd(self): if not self.simulate: self.mote.clear() self.mote.show() self.showMessage("Lights Finished") self.completeRepeats += 1 if self.bControlCamera: while self.bCameraBusy: pass message = "Show " + str(self.completeRepeats) + "/" + str( self.iRepeats) + " Complete in " + str(time.time() - self.startTime) + "s" self.showMessage(message) try: self.im.seek(self.im.tell() + 1) self.rgb_im = self.im.convert('RGB').resize( (self.timeSlices, self.iPixels)) self.refreshPixels() self.showMessage("Loaded next frame") self.drawPreview() except EOFError: try: if (self.im.tell() > 0): self.im.seek(0) self.rgb_im = self.im.convert('RGB').resize( (self.timeSlices, self.iPixels)) self.refreshPixels() print("Animation Looped") except: if (self.im.tell() > 0): self.im = Image.open(self.filename) self.rgb_im = self.im.convert('RGB').resize( (self.timeSlices, self.iPixels)) self.refreshPixels() print("Could not loop - Reloaded") if (self.completeRepeats < self.iRepeats): self.singleShow() else: self.completeRepeats = 0 self.makeRandom() self.drawPreview() def startPhoto(self): if self.bControlCamera: thread.start_new_thread(self.takePhoto, ()) def show(self): self.canPreview.create_rectangle( 0, 0, self.graphWidth, (len(self.yToStick) * self.motePixelInSceenPixels), fill="#000") if self.simulate: message = "Simulating" else: message = "Show " + str(self.completeRepeats + 1) + "/" + str( self.iRepeats) + " started" self.showMessage(message) duration = float(self.scaDuration.get()) self.stepTime = int(1000 * duration / float(self.timeSlices)) self.stepTimeS = duration / float(self.timeSlices) self.currentColumn = 0 self.startTime = time.time() self.targetTime = time.time() + self.stepTimeS self.doColumn() def doColumn(self): if time.time() < self.targetTime: self.timer = self.mainwindow.after(1, self.doColumn) return thisColumn = self.currentColumn if self.currentColumn < self.graphWidth: self.targetTime += self.stepTimeS self.timer = self.mainwindow.after(1, self.doColumn) self.drawColumn(thisColumn) self.showColumn(thisColumn) else: self.onShowEnd() self.currentColumn += 1 def showMessage(self, message): self.builder.tkvariables.__getitem__('messageText').set(message) def on_btnDraw_clicked(self, event=None): if (self.currentColumn > 0 and self.currentColumn < self.graphWidth) or self.bCameraBusy: self.showMessage("Cannot start now, still running") return False self.updateParams() self.completeRepeats = 0 self.singleShow() def drawCountdown(self): i = 1 + self.iFullDelay - self.delayRemaining width = self.graphWidth if self.iFullDelay > 0: width = i * self.graphWidth / self.iFullDelay self.canPreview.create_rectangle( 0, 0, width, (len(self.yToStick) * self.motePixelInSceenPixels), fill="#000") message = "Show " + str(self.completeRepeats + 1) + "/" + str( self.iRepeats) + " starts in " + str(self.delayRemaining) self.canPreview.itemconfigure(self.countdown_id, text=message) self.showMessage(message) if self.delayRemaining <= 4 and self.delayRemaining > 1: self.beep(0.1) self.delayRemaining -= 1 if self.delayRemaining > 0: self.mainwindow.after(1000, self.drawCountdown) else: self.beep(0.3) def singleShow(self): if self.simulate: self.connectToMote() self.canPreview.create_rectangle( 0, 0, self.graphWidth, (len(self.yToStick) * self.motePixelInSceenPixels), fill="#AAA") self.countdown_id = self.canPreview.create_text(100, self.graphWidth - 100, fill="#F00", text=".....") delayTime = self.scaDelay.get() lag = 0 if self.bControlCamera: lag = self.cameraLag #Start the countdown including the lag self.iFullDelay = delayTime + lag self.delayRemaining = self.iFullDelay self.drawCountdown() #start the camera shot after the delay without the lag self.mainwindow.after(delayTime * 1000, self.startPhoto) #start the show after waiting for delay & lag self.mainwindow.after((delayTime + lag) * 1000, self.show) def run(self): self.mainwindow.mainloop()
return gauss try: while True: for z in list(range(1, 10)[::-1]) + list(range(1, 10)): fwhm = 7.0 / z gauss = make_gaussian(fwhm) start = time.time() y = 4 for x in range(16): h = 0.5 s = 1.0 v = gauss[x, y] rgb = colorsys.hsv_to_rgb(h, s, v) r, g, b = [int(255.0 * i) for i in rgb] mote.set_pixel(1, x, r, g, b) mote.set_pixel(2, x, r, g, b) mote.set_pixel(3, x, r, g, b) mote.set_pixel(4, x, r, g, b) mote.show() end = time.time() t = end - start if t < 0.04: time.sleep(0.04 - t) except KeyboardInterrupt: mote.clear() mote.show() quit()
m = Mote() m.set_clear_on_exit(True) m.configure_channel(1, 16, False) m.configure_channel(2, 16, False) m.configure_channel(3, 16, False) m.configure_channel(4, 16, False) m.clear() try: while True: clear = random.randint(0, 9) if clear == 0: m.clear() for channel in range(1, 5): pixel = random.randint(0, 15) red = random.randint(0, 255) green = random.randint(0, 255) blue = random.randint(0, 255) delay = random.randint(2, 20) m.set_pixel(channel, pixel, red, green, blue, 0.5) m.show() time.sleep(delay / 1000) except KeyboardInterrupt: m.clear() m.show()
last_r = 0 last_g = 0 last_b = 0 while True: for c in range(1, 5): for p in range(16): while True: r = random.choice([0, 127, 255]) g = random.choice([0, 127, 255]) b = random.choice([0, 127, 255]) if (r != g or r != b or g != b) and (r != last_r and b != last_b and g != last_g): break m.set_pixel(c, p, r, g, b) last_r = r last_g = g last_b = b # clear next pixel ready for next loop if p < 15: m.set_pixel(c, p + 1, 0, 0, 0) m.show() time.sleep(0.05) pass time.sleep(0.05) m.show() time.sleep(0.05)
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) try: for i in range(500): h = time.time() * 50 for channel in range(4): for pixel in range(16): hue = (h + (channel * 64) + (pixel * 4)) % 360 r, g, b = [int(c * 255) for c in hsv_to_rgb(hue/360.0, 1.0, 1.0)] mote.set_pixel(channel + 1, pixel, r, g, b) mote.show() time.sleep(0.01) mote.clear() mote.show() for i in range(0, 15, 2): mote.set_pixel(1, i, 255, 255, 255) mote.set_pixel(2, i+1, 255, 255, 255) mote.set_pixel(3, i, 255, 255, 255) mote.set_pixel(4, i+1, 255, 255, 255) mote.show() time.sleep(1) Flotilla.motor(63) GPIO.output(2, GPIO.HIGH) time.sleep(0.5) GPIO.output(2, GPIO.LOW)
mote.configure_channel(2, 16, False) mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) def usage(): print("Usage: {} <r> <g> <b>".format(sys.argv[0])) sys.exit(1) if len(sys.argv) != 4: usage() # Exit if non integer value. int() will raise a ValueError try: r, g, b = [int(x) for x in sys.argv[1:]] except ValueError: usage() # Exit if any of r, g, b are greater than 255 if max(r,g,b) > 255: usage() print("Setting Mote to {r},{g},{b}".format(r=r,g=g,b=b)) for channel in range(4): for pixel in range(16): mote.set_pixel(channel + 1, pixel, r, g, b) time.sleep(0.01) mote.show()
## Author: Daniel Pullan ## Github: GitHub.com/DanielPullan ## Website: DanielPullan.co.uk from time import sleep from mote import Mote mail = int(feedparser.parse("https://" + email + ":" + password + "@mail.google.com/gmail/feed/atom/")["feed"] ["fullcount"]) 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) # stripnumber, pixel number (0 is first), red, green, blue # mote.set_pixel(1, 1, 255, 0 0) = on first strip, second pixel, red = 255, blue and green = 0 mote.clear() for pixel in range(16): mote.set_pixel(1, pixel, 0,0,0) mote.show()
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() time.sleep(0.1)
#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)
#Coded by TB - 2016 import random import time 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) try: while True: for channel in range(4): pixels = random.sample(range(16), random.randint(1, 5)) for i in range(16): if i in pixels: mote.set_pixel(channel + 1, i, 255, 255, 0) else: mote.set_pixel(channel + 1, i, 0, 0, 0) mote.show() time.sleep(0.15) except KeyboardInterrupt: mote.clear() mote.show() quit()
mote.configure_channel(2, 16, False) mote.configure_channel(3, 16, False) mote.configure_channel(4, 16, False) elif args.output == status_phat: print '--status_phat er ikke implementeret endnu' exit(1) elif args.output == status_hat: print '--status_hat er ikke implementeret endnu' exit(1) import json import time import requests loop = True while loop: mote.clear() print "=============================" response = requests.get(args.url) beats = json.loads(response.text) for beat in beats: channel = beat["sorting"] / 16 + 1 led = beat["sorting"] % 16 if channel <= 4: mote.set_pixel(channel, led, beat["r"], beat["g"], beat["b"]) print channel, led, beat["color"] mote.show() time.sleep(1) loop = args.loop
# Adapted from blinkt example import random import time 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) try: while True: for channel in range(4): for i in range(16): mote.set_pixel(channel+1,i, random.randint(0,255), random.randint(0,255), random.randint(0,255)) time.sleep(0.01) mote.show() except KeyboardInterrupt: mote.clear() mote.show() quit()
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)
tot_cases_yesterday = int(data[-2]['Cases']) new_cases_today = tot_cases_today - tot_cases_yesterday print('Updated new cases today:', new_cases_today) return str(bin(new_cases_today))[2:] mote = Mote() mote.configure_channel(1, 16, False) last_case_str = None mote.clear() while True: cases_bin = new_cases_today_bin() if (not last_case_str) or cases_bin != last_case_str: print('Cases changed, updating display...') for i, v in enumerate(cases_bin): if v == '1': mote.set_pixel(1, i, 255, 255, 255, 0.02) else: mote.set_pixel(1, i, 0, 0, 0, 0) mote.show() else: print('Cases unchanged.') print('Sleeping for {} seconds...'.format(sleep_time)) sleep(sleep_time)
channels = [0, 1, 2, 3] #mote.set_brightness(0.2) x = 0 while x < 5: print("doing a rainbow for 15 seconds") current_time = datetime.now() while datetime.now() < (current_time + timedelta(seconds=10)): h = time.time() * 50 for channel in range(4): for pixel in range(16): hue = (h + (channel * 64) + (pixel * 4)) % 360 r, g, b = [ int(c * 255) for c in hsv_to_rgb(hue / 360.0, 1.0, 1.0) ] mote.set_pixel(channel + 1, pixel, r, g, b) mote.show() time.sleep(0.01) print("rainbow time over") print("lights out - clear and show - for 10 seconds") mote.clear() mote.show() time.sleep(10) print("lights on for 10 seconds") for channel in channels: for pixel in range(16): mote.set_pixel(channel, pixel, 150, 150, 150) mote.show() time.sleep(10) print("lights out - set 0 bright and clear - for 10 seconds") #mote.set_brightness(0)