def option_1():###User enters a sentance to create the light show### phrase = raw_input("Please enter your phrase ").lower() ###Checks the letters in the phrase, then works out the co- ordinates### for letter in phrase: index = ord(letter)-65 #print index ### remove when complete### if index > 0: x = int(index/8.0) #print x ### remove when complete### x = x - 4 y = int(index%8) #print (x, y) UH.clear UH.brightness(0.20) UH.set_pixel(y, x, 255, 255, 255) #UH.set_pixel(x, y, 0, 255, 0) UH.show() time.sleep(0.5) UH.clear() elif index <= 0: random_sparkle()
def kick_rainbow(): random_r = randint(0,255) random_g = randint(0,255) random_b = randint(0,255) random_math_r = randint(32,640) random_math_g = randint(32,640) random_math_b = randint(32,640) bright = 1 i = 0.0 offset = 30 for q in range(20): #splash a kick for 20 revs i = i + 0.3 for y in range(4): for x in range(8): r = 0#x * 32 g = 0#y * 32 xy = x + y / 4 r = (math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64 + 128.0 g = (math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64 + 128.0 b = (math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64 + 128.0 r = max(0, min(random_r, r + offset)) g = max(0, min(random_g, g + offset)) b = max(0, min(random_b, b + offset)) unicorn.set_pixel(x,y,int(r),int(g),int(b)) unicorn.brightness(bright) unicorn.show() time.sleep(0.001) if bright > 0.3: bright = bright - 0.01 #fade on each pass until black unicorn.clear()
def go(): unicorn.brightness(1) unicorn.rotation(90) wrd_rgb = [[154, 173, 154], [0, 255, 0], [0, 200, 0], [0, 162, 0], [0, 145, 0], [0, 96, 0], [0, 74, 0], [0, 0, 0,]] clock = 0 blue_pilled_population = [[randint(0,7), 7]] t_end = time.time() + 10 while time.time() < t_end: for person in blue_pilled_population: y = person[1] for rgb in wrd_rgb: if (y <= 7) and (y >= 0): unicorn.set_pixel(person[0], y, rgb[0], rgb[1], rgb[2]) y += 1 person[1] -= 1 unicorn.show() time.sleep(0.1) clock += 1 if clock % 5 == 0: blue_pilled_population.append([randint(0,7), 7]) if clock % 7 == 0: blue_pilled_population.append([randint(0,7), 7]) while len(blue_pilled_population) > 100: blue_pilled_population.pop(0)
def option_2():###Select a website to create the light show your_webiste_choice = raw_input("Please enter the web address") final_address = "http://%s" %(your_webiste_choice) print "finding", final_address website = urllib2.urlopen(final_address ) ##print website.read() sentence = website.read() print sentence ###Checks the letters in the website, then works out the co- ordinates### for letter in sentence: index = ord(letter)-65 #print index ### remove when complete### if index > 0: x = int(index/8.0) #print x ### remove when complete### #x = x - 4 y = int(index%8) #print (x, y) UH.clear UH.brightness(0.2) UH.set_pixel(y, x, 0, 255, 0) UH.set_pixel(x, y, 0, 255, 0) UH.show() time.sleep(0.02) UH.clear() elif index <= 0: random_sparkle()
def __init__(self): self._logger = logging.getLogger(self.__class__.__name__) self._current_value = self.BLUE UH.brightness(1.0) pixels = self._set_whole_grid(self._current_value) UH.set_pixels(pixels) UH.show()
def go(): effects = [tunnel, rainbow_search, checker, swirl] unicorn.brightness(1) step = 0 t_end = time.time() + 10 while time.time() < t_end: for i in range(500): for y in range(8): for x in range(8): r, g, b = effects[0](x, y, step) if i > 400: r2, g2, b2 = effects[-1](x, y, step) ratio = (500.00 - i) / 100.0 r = r * ratio + r2 * (1.0 - ratio) g = g * ratio + g2 * (1.0 - ratio) b = b * ratio + b2 * (1.0 - ratio) r = int(max(0, min(255, r))) g = int(max(0, min(255, g))) b = int(max(0, min(255, b))) unicorn.set_pixel(x, y, r, g, b) step += 1 unicorn.show() time.sleep(0.01) effect = effects.pop() effects.insert(0, effect)
def __init__(self): self.prefs_file = "prefs.json" self.prefs = {} print("Clock online") self.__load_preferences() UH.brightness(self.prefs['brightness']) self.t = None
def go(): UH.brightness(1) for y in range(8): for x in range(8): UH.set_pixel(x,y,255,0,0) UH.show() time.sleep(0.05) time.sleep(1)
def setBrightness(currenttime): currenthour = currenttime.tm_hour # if it's between 10 am and 8 pm, # use dimmer brightness if(currenthour < 10 or currenthour > 20): unicorn.brightness(0.5) else: unicorn.brightness(1)
def __init__(self, go_server, buildname): self.go_server = go_server self.buildname = buildname self.logger = logging.getLogger(__name__ + '.Monitor') self.logger.debug("Monitoring {0}".format(buildname)) self.swirly = Swirly() UH.brightness(0.2) self.building_event = None
def show_all_pixels(r, g, b, brightness=0.5): unicornhat.brightness(brightness) grid = [ [(r, g, b) for col in xrange(NUM_COLS)] for row in xrange(NUM_ROWS) ] unicornhat.set_pixels(grid) unicornhat.show()
def flashit(time_to_flash,steps): for j in range(0,steps): steps = float(steps * 1.0) brightness = float(j/steps) print j,brightness print time_to_flash unicorn.brightness(brightness) unicorn.show() time.sleep(time_to_flash/(j+1)) unicorn.clear() unicorn.brightness(0.1)
def showflaggreen(): pixels = [[(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)], [(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)], [(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)], [(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)], [(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)], [(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)], [(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)], [(0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0), (0, 255, 0)]] unicornhat.set_pixels(pixels) unicornhat.brightness(0.1) unicornhat.show()
def showflagblue(): pixels = [[(132, 132, 0), (132, 132, 0), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132)], [(132, 132, 0), (132, 132, 0), (132, 132, 0), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132)], [(0, 0, 132), (132, 132, 0), (132, 132, 0), (132, 132, 0), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132)], [(0, 0, 132), (0, 0, 132), (132, 132, 0), (132, 132, 0), (132, 132, 0), (0, 0, 132), (0, 0, 132), (0, 0, 132)], [(0, 0, 132), (0, 0, 132), (0, 0, 132), (132, 132, 0), (132, 132, 0), (132, 132, 0), (0, 0, 132), (0, 0, 132)], [(0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (132, 132, 0), (132, 132, 0), (132, 132, 0), (0, 0, 132)], [(0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (132, 132, 0), (132, 132, 0), (132, 132, 0)], [(0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (0, 0, 132), (132, 132, 0), (132, 132, 0)]] unicornhat.set_pixels(pixels) unicornhat.brightness(0.1) unicornhat.show()
def showflagwhite(): pixels = [[(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255)]] unicornhat.set_pixels(pixels) unicornhat.brightness(0.1) unicornhat.show()
def showflagdoubleyellow(): pixels = [[(255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0)], [(255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0)], [(255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0)], [(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)], [(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)], [(255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0)], [(255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0)], [(255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0), (255, 255, 0)]] unicornhat.set_pixels(pixels) unicornhat.brightness(0.1) unicornhat.show()
def showflagblack(): pixels = [[(255, 255, 255), (255, 255, 255), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (0, 0, 0), (0, 0, 0), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(0, 0, 0), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (0, 0, 0)], [(0, 0, 0), (0, 0, 0), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (0, 0, 0), (0, 0, 0)], [(0, 0, 0), (0, 0, 0), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (0, 0, 0), (0, 0, 0)], [(0, 0, 0), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (0, 0, 0)], [(255, 255, 255), (255, 255, 255), (255, 255, 255), (0, 0, 0), (0, 0, 0), (255, 255, 255), (255, 255, 255), (255, 255, 255)], [(255, 255, 255), (255, 255, 255), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (255, 255, 255), (255, 255, 255)]] unicornhat.set_pixels(pixels) unicornhat.brightness(0.1) unicornhat.show()
def play(xml_path, brightness=0.2, no_unicorns=False, verbose=False): """This script parses a TEI XML encoded play, and applies sentiment analysis to each speech. The result of the sentiment analysis is displayed on the Unicorn HAT - one pixel per speech - using a range of colours from red (negative sentiment) to blue (positive sentiment).""" unicorns = not no_unicorns if unicorns: uh.brightness(brightness) lines = _get_lines_from_xml(xml_path) for idx, line in enumerate(lines): _process_line(idx, line, unicorns, verbose)
def change_color(color): r = color['r'] g = color['g'] b = color['b'] a = color['a'] logger.debug("Setting to r:%d g:%d b:%d brightness:%.2f" % (r,g,b,a)) unicorn.brightness(a) for y in range(8): for x in range(8): unicorn.set_pixel(x,y,int(r),int(g),int(b)) unicorn.show()
def go(): unicorn.brightness(1) t_end = time.time() + 10 while time.time() < t_end: for z in list(range(1, 10)[::-1]) + list(range(1, 10)): fwhm = 5.0/z gauss = make_gaussian(fwhm) for y in range(8): for x in range(8): h = 1.0/(x + y + 1) s = 0.8 v = gauss[x,y] rgb = colorsys.hsv_to_rgb(h, s, v) r = int(rgb[0]*255.0) g = int(rgb[1]*255.0) b = int(rgb[2]*255.0) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.005)
def hihat_splash(): unicorn.brightness(1) y_loc = randint(0,2) x_loc = randint(0,6) red = randint(192,255) gre = randint(192,255) blu = randint(192,255) unicorn.set_pixel(x_loc, y_loc, red, gre, blu) unicorn.set_pixel((x_loc + 1), y_loc, red, gre, blu) unicorn.set_pixel((x_loc + 1), (y_loc + 1), red, gre, blu) unicorn.set_pixel(x_loc, (y_loc + 1), red, gre, blu) for p in range(7): red2 = randint(0,255) gre2 = randint(0,255) blu2 = randint(0,255) unicorn.set_pixel(randint(0,8), randint(0,4), red2, gre2, blu2) unicorn.show() time.sleep(0.05) unicorn.clear() unicorn.show()
def pulse_color( color=(255, 255, 255), brightness=0.8, total_time=1, step_time=0.01): """ Set all LCDs to green. :param color: tuple representing color as (R,G,B) :param brightness: max brightness value of pulse (0-1) :param total_time: time for full color pulse to complete, in seconds :param step_time: step time between brightness updates, in seconds """ unicornhat.brightness(0) # initial pulse value is 0 unicornhat.set_all(color) unicornhat.show() # Calculate pulse data steps_half = int(total_time / step_time / 2) print('Half steps: {}'.format(steps_half)) delta_brightness = brightness / steps_half # Start pulse up for _ in range(steps_half): brightness = unicornhat.get_brightness() + delta_brightness if brightness > 1: brightness = 1 # ensure max limit (in case of steps_half rounding) unicornhat.brightness(brightness) unicornhat.show() time.sleep(step_time) # Start pulse down for _ in range(steps_half): brightness = unicornhat.get_brightness() - delta_brightness if brightness < 0: brightness = 0 # ensure min limit (in case of steps_half rounding) unicornhat.brightness(brightness) unicornhat.show() time.sleep(step_time)
def gradual_light_on(seconds): sleep_time = seconds / 200.0 brightness_step = (brightness_end - brightness_start) / 200.0 brightness_level = brightness_start # Set all the pixels to the yellowish colour r, g, b = colorsys.hsv_to_rgb(0.108, 0.6, 1.0) r = int(r * 255) g = int(g * 255) b = int(b * 255) for y in range(8): for x in range(8): unicornhat.set_pixel(x, y, r, g, b) unicornhat.brightness(brightness_start) unicornhat.show() # Increase brightness gradually while brightness_level < brightness_end: unicornhat.brightness(brightness_level) unicornhat.show() brightness_level += brightness_step time.sleep(sleep_time)
def init(config_file_name=''): global width, height, total_pages, pages, current_page, palette, current_channel unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) unicorn.brightness(0.5) current_page = 0 current_channel = ["default", "startup", ""] width, height = unicorn.get_shape() with open('res/colors.json') as json_data: palette = json.load(json_data) if not os.path.isfile(config_file_name): config_file_name = 'res/config.default.json' with open(config_file_name) as config: data = json.load(config) pages = data["Pages"] total_pages = len(pages) print "Unicorn started" print "there are", total_pages, "pages" print "Autoscan", data["Autoscan"] set_autoscan(data["Autoscan"])
def house(r,g,b): UH.off() UH.rotation(180) UH.brightness(0.5) global working working = True UH.set_pixel(4,0,r,g,b) UH.set_pixel(3,1,r,g,b) UH.set_pixel(4,1,r,g,b) UH.set_pixel(2,2,r,g,b) UH.set_pixel(3,2,r,g,b) UH.set_pixel(4,2,r,g,b) UH.set_pixel(5,2,r,g,b) UH.set_pixel(1,3,r,g,b) UH.set_pixel(2,3,r,g,b) UH.set_pixel(3,3,r,g,b) UH.set_pixel(4,3,r,g,b) UH.set_pixel(5,3,r,g,b) UH.set_pixel(6,3,r,g,b) UH.set_pixel(0,4,r,g,b) UH.set_pixel(1,4,r,g,b) UH.set_pixel(6,4,r,g,b) UH.set_pixel(7,4,r,g,b) UH.set_pixel(1,5,r,g,b) UH.set_pixel(6,5,r,g,b) UH.set_pixel(1,6,r,g,b) UH.set_pixel(4,6,r,g,b) UH.set_pixel(6,6,r,g,b) UH.set_pixel(1,7,r,g,b) UH.set_pixel(2,7,r,g,b) UH.set_pixel(3,7,r,g,b) UH.set_pixel(4,7,r,g,b) UH.set_pixel(5,7,r,g,b) UH.set_pixel(6,7,r,g,b) UH.show() time.sleep(2) UH.off() working = False
def main(): unicorn.set_layout(unicorn.PHAT) unicorn.rotation(90) unicorn.brightness(0.4) renderer = Renderer(unicorn) # Fetch the Dow Jones Industrial Average list of 30 components dow = fetchQuotes(['^DJI'], ['components']) dow30_tickers = dow[0]['components'] # There are 32 pixels, so add 2 more items dow30_tickers.append('AMZN') dow30_tickers.append('FB') print("Fetching Dow 30, and 2 more: %s" % dow30_tickers) dow_30 = fetchQuotes(dow30_tickers) components = ComponentList() for quote in dow_30: change = quote['regularMarketChangePercent'] if 'regularMarketChangePercent' in quote else 0 mktCap = quote['marketCap'] if 'marketCap' in quote else 0 print("%s: %f %d" % (quote['symbol'], change, mktCap)) comp = Component(quote['symbol']) comp.quote = { 'change_percent': change, 'market_cap': mktCap } components.append(comp) components.sort(ComponentList.SortKey.MARKET_CAP) renderer.render(components) streamer = Streamer(renderer, components) asyncio.get_event_loop().run_until_complete(asyncio.gather( #rotateLayout(renderer, components), streamer.connect() ))
def main( offset=30, brightness=1, brightness_step=0.001, brightness_shutoff=0.4, tick_max=120000, cycle_period=0.03, hue_step=0.005): offset = offset + 128 for tick in itertools.count(): cycle_end = time.time() + cycle_period if brightness <= brightness_shutoff: unicorn.off() time.sleep(tick_max / cycle_period / 1000) os.system('shutdown -h now') if tick > tick_max: brightness -= brightness_step unicorn.brightness(brightness) set_hat_color(tick * hue_step, level_boost=offset) time.sleep(max(time.time() - cycle_end, 0))
def set_lights(r, g, b, brightness, speed): if brightness != '': uh.brightness(brightness) for y in range(height): for x in range(width): uh.set_pixel(x, y, r, g, b) uh.show() if speed != '': sleep(speed) uh.clear() crntT = threading.currentThread() while getattr(crntT, "do_run", True): for y in range(height): for x in range(width): uh.set_pixel(x, y, r, g, b) uh.show() sleep(speed) uh.clear() uh.show() sleep(speed)
def updateState(data): squares = data['squares'] # iterate through array and find the lights, turn them on. unicorn.set_layout(unicorn.AUTO) unicorn.rotation(180) unicorn.brightness(0.6) for square in squares: if square['isSelected']: x = square['coords'][0] y = square['coords'][1] r = square['color']['r'] g = square['color']['g'] b = square['color']['b'] unicorn.set_pixel(x, y, r, g, b) send_colors_to_shirt(squares) unicorn.show() time.sleep(7) unicorn.off()
def rain(): UH.off() UH.brightness(0.5) UH.rotation(0) wrd_rgb = [[115, 115, 255], [0, 0, 255], [0, 0, 200], [0, 0, 162], [0, 0, 145], [0, 0, 96], [0, 0, 74], [0, 0, 0,]] clock = 0 blue_pilled_population = [[randint(0,7), 7]] while clock <= 60: for person in blue_pilled_population: y = person[1] for rgb in wrd_rgb: if (y <= 7) and (y >= 0): UH.set_pixel(person[0], y, rgb[0], rgb[1], rgb[2]) y += 1 person[1] -= 1 UH.show() time.sleep(0.1) clock += 1 if clock % 5 == 0 and clock <= 50: blue_pilled_population.append([randint(0,7), 7]) UH.off()
def main(): global width, height mqttclient = mqtt.Client() # Assign event callbacks mqttclient.on_connect = on_connect mqttclient.on_subscribe = on_subscribe mqttclient.on_message = on_message # Connect mqttclient.username_pw_set(settings.MQTT_USERNAME, settings.MQTT_PASSWORD) mqttclient.connect(settings.MQTT_HOST, int(settings.MQTT_PORT)) # Start subscription mqttclient.subscribe('rgb/+') unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) unicorn.brightness(1) width, height = unicorn.get_shape() mqttclient.loop_forever(timeout=1.0, max_packets=1, retry_first_connection=False)
def setBrightness(currenttime): currenthour = currenttime.tm_hour # if it's between 10 am and 8 pm, # use dimmer brightness if(currenthour < 7 or currenthour > 22): unicornhat.brightness(0.2) elif (currenthour > 7 and currenthour < 16): unicornhat.brightness(0.8) else: unicornhat.brightness(0.4)
def pulse(times): for i in range(times): unicornhat.brightness(0.9) for b in range(90, 59, -1): unicornhat.brightness(b/100) unicornhat.show() sleep(0.04) for b in range(60, 91, 1): unicornhat.brightness(b/100) unicornhat.show() sleep(0.04)
def draw_history_to_unicorn(): global history counter = 0 if unicorn_detected: yrange = range(height) if unicornhd_detected: yrange = range(height - 1, -1, -1) for y in yrange: for x in range(width): # if we have an item in history for this position if counter < len(history): # pull the data out of the history pm25_float_from_history = history[counter] rgb_dict = pm25_to_rgb(pm25_float_from_history) # set the pixel color to the purpleair color unicorn.set_pixel(x, y, rgb_dict["r"], rgb_dict["g"], rgb_dict["b"]) counter = counter + 1 # change unicorn brightness based on time of day hour = dt.datetime.now().hour #print("hour is " + str(hour)) if (hour >= 22 or hour < 8): if unicornhd_detected: unicorn.brightness(0.1) else: unicorn.brightness(0.3) else: unicorn.brightness(0.5) # flush the changes out to the unicorn hat unicorn.show()
This basic example shows use of the Python Pillow library: sudo apt-get install pillow The tiny 8x8 chars in lofi.png are from Oddball: http://forums.tigsource.com/index.php?topic=8834.0 Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. ''' import unicornhat as unicorn from PIL import Image import signal, numpy, time unicorn.rotation(90) unicorn.brightness(0.4) img = Image.open('lofi.png') for o_x in range(img.size[0]/8): for o_y in range(img.size[1]/8): for x in range(8): for y in range(8): pixel = img.getpixel(((o_x*8)+y,(o_y*8)+x)) print(pixel) r, g, b = int(pixel[0]),int(pixel[1]),int(pixel[2]) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.5)
from PIL import Image from time import sleep import unicornhat as unicorn import numpy unicorn.brightness(1) unicorn.rotation(180) unicorn.clear() unicorn.show() unicorn.set_pixel(9, 0, 0, 0, 255) #blue unicorn.show() sleep(3) file = input("Please enter the name of the file ") im = Image.open(file + ".jpg", "r") # name of file to scan width, height = im.size pixel_values = list(im.getdata()) print(pixel_values) total = (len(pixel_values)) #pixel_list = pixel_values print("Found ", total, "Pixels") if total == 100: unicorn.set_pixel(9, 0, 255, 0, 0) unicorn.show() sleep(3) npc = [] # list to stored new RGB values New Pixel Colours # Sorts GRB values into RGB values for i in range(0, 100):
def __init__(self): unicorn.set_layout(unicorn.HAT) unicorn.rotation(90) unicorn.brightness(1) self.width, self.height = unicorn.get_shape()
STUDY_LOOP = False LOOP = False TUNNEL_GAP_MIN = 2 TUNNEL_GAP_MAX = 3 TUNNEL_GAP_DIFF_MAX = 1 TUNNEL_MOVE_DIFF_MAX = 1 AI_VISIBILITY_DEPTH = 4 AI_REROUTE_DEPTH = 4 if SCREEN_TYPE == "UNICORN": import unicornhat as unicorn unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) unicorn.brightness(0.7) SCREEN_WIDTH, SCREEN_HEIGHT = unicorn.get_shape() screen_size = (SCREEN_WIDTH, SCREEN_HEIGHT) RGB_ENABLED = True BG_COLOR = [0, 150, 200] BG_NOISE = 2 CAVE_COLOR = [244, 164, 96] CAVE_NOISE = 10 PLAYER_COLOR = [255, 0, 0] if SCREEN_TYPE == "SCROLL": import scrollphat SCREEN_WIDTH = 11 SCREEN_HEIGHT = 5 scrollphat.set_brightness(1)
def __init__(self, generate): self.generate_pixels = generate phat.set_layout(phat.AUTO) phat.rotation(0) phat.brightness(0.3) self.width, self.height = phat.get_shape()
def setBrightness(self, brightness): unicornhat.brightness(brightness)
import unicornhat as uh import random import time uh.set_layout(uh.PHAT) uh.brightness(0.5) while True: for i in range(8): for j in range(4): r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) uh.set_pixel(i, j, r, g, b) uh.show() time.sleep(0.5)
#!/usr/bin/env python import unicornhat as unicorn import time, colorsys import math unicorn.brightness(0.5) def compute_z(x, y, t): x = x + t y = y + t h, w = 2, 2 z = (128.0 + (128.0 * math.sin(x / 16.0)) + 128.0 + (128.0 * math.sin(y / 32.0)) \ + 128.0 + (128.0 * math.sin(math.sqrt((x - w / 2.0) * (x - w / 2.0) + (y - h / 2.0) * (y - h / 2.0)) / 8.0)) \ + 128.0 + (128.0 * math.sin(math.sqrt(x * x + y * y) / 8.0))) % 255 / 255 return z t = 0 while True: for y in range(8): for x in range(8): h = compute_z(x, y, t) s = 1.0 v = 0.4 rgb = colorsys.hsv_to_rgb(h, s, v) r = int(rgb[0]*255.0) g = int(rgb[1]*255.0) b = int(rgb[2]*255.0) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.05)
This basic example shows use of the Python Pillow library: sudo pip-3.2 install pillow # or sudo pip install pillow The tiny 8x8 chars in lofi.png are from Oddball: http://forums.tigsource.com/index.php?topic=8834.0 Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. ''' import unicornhat as unicorn from PIL import Image import signal, numpy, time unicorn.rotation(90) unicorn.brightness(0.9) img = Image.open('lofi.png') for o_x in range(int(img.size[0]/8)): for o_y in range(int(img.size[1]/8)): for x in range(8): for y in range(8): pixel = img.getpixel(((o_x*8)+y,(o_y*8)+x)) print(pixel) r, g, b = int(pixel[0]),int(pixel[1]),int(pixel[2]) unicorn.set_pixel(x, y, r, g, b) unicorn.show() time.sleep(0.5)
import unicornhat as uh import time import serial import random from random import randint uh.set_layout(uh.PHAT) uh.brightness(0.5) ser = serial.Serial('/dev/ttyAMA0', baudrate=38400) #original #ser = serial.Serial('/dev/ttyAMA0') # bens first one, doesnt seem to work #ser = serial.Serial('/dev/ttyAMA0', baudrate=31250) #sees program change? #ser = serial.Serial('/dev/ttyAMA0', baudrate=38400) # my try on jani comment # THIS IS KIND OF WORKING - i DON'T KNOW WHY 23 IS THE BEAT RATE, BUT IT SEEMS RIGHT. message = [0, 0, 0] clock_count = 0 while True: i = 0 while i < 3: data = ord(ser.read(1)) # read a byte # if data != 240: # i think 240 is the bpm? # print data # me if data == 14 or data == 142: for y in range(4): for x in range(8): uh.set_pixel(x,y,randint(0,255),randint(0,255),randint(0,255)) uh.show() if data == 240: # changed this to 240, trying to get the clock clock_count += 1
for y in range(4): for x in range(4, 8): uphat.set_pixel(x, y, levels[l_tomorrow][0], levels[l_tomorrow][1], levels[l_tomorrow][2]) # This is where the script starts # Set unicorn phat LEDs uphat.set_layout( uphat.PHAT ) # Library works for both HAT and pHAT, we choose the second one uphat.rotation( 180 ) # If your Zero power USB is on the top side use this setting, else set to 0 uphat.brightness( 1 ) # WARNING: if you're not using the diffuser, don't set this to more than 0.5!!!! # Run forever :-) while True: # Get RSS feed for Croatia - change the code for other countries, e.g. 'de' for Germany rss = getRssFeed('hr') # Get region index from RSS feed i = getRssFeedIndex('North Dalmatia region') # Get warning levels for the selected region getWarningLevels() # If everything works fine, you can comment out the next line showData() # Set LED colors according to warnning levels for today and tomorrow setLedColors() # Finnaly, show the colors
import unicornhat as uc import time uc.brightness(.5) uc.rotation(180) x = 0 Y = 0 try: while 1: uc.set_pixel(x, Y, 128, 0, 0) uc.set_pixel(x - 1, Y, 0, 0, 0) uc.show() time.sleep(.3) if x < 8: x = (x + 1) elif x == 8: x = 0 uc.off() except KeyboardInterrupt: uc.off()
#!/usr/bin/python import unicornhat as unicorn import time import sys unicorn.rotation(180) # adjust for your Pi's orientation unicorn.brightness(0.4) # warning: altering this value can make the LED very bright! font_dictionary={' ': [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], '$': [[0.15, 1, 1, 1, 0.15], [1, 0.15, 1, 0.15, 1], [1, 0.15, 1, 0, 0.15], [0.15, 1, 1, 0.75, 0.15], [0.15, 0, 1, 0.15, 1], [1, 0.15, 1, 0.15, 1], [0.15, 1, 1, 1, 0.15], [0, 0, 1, 0, 0]], '(': [[0, 0.75, 0.15], [0.15, 0.75, 0], [0.75, 0.15, 0], [1, 0.15, 0], [1, 0, 0], [1, 0.15, 0], [0.75, 0.15, 0], [0.15, 0.75, 0]], ',': [[0], [0], [0], [0], [0], [0], [1], [1]], '0': [[0.15, 0.75, 1, 0.75, 0.15], [0.75, 0.75, 0.15, 0.75, 0.75], [1, 0.15, 0, 0.15, 1], [1, 0, 0, 0, 1], [1, 0.15, 0, 0.15, 1], [0.75, 0.75, 0.15, 0.75, 0.75], [0.15, 0.75, 1, 0.75, 0.15], [0, 0, 0, 0, 0]], '4': [[0, 0.15, 1, 0], [0, 0.15, 1, 0], [0, 0.15, 1, 0], [0.15, 0, 1, 0], [0.15, 0, 1, 0], [1, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 0]], '8': [[0.15, 1, 1, 1, 0.15], [1, 0.15, 0, 0.15, 1], [1, 0.15, 0, 0.15, 1], [0.15, 1, 1, 1, 0.15], [1, 0.15, 0, 0.15, 1], [1, 0.15, 0, 0.15, 1], [0.15, 1, 1, 1, 0.15], [0, 0, 0, 0, 0]], '<': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0.15], [0, 0, 0.15, 0.75, 0.75], [0.15, 0.75, 0.15, 0, 0], [0.15, 0.75, 0.75, 0.15, 0], [0, 0, 0.15, 0.75, 0.75], [0, 0, 0, 0, 0]], '@': [[0, 1, 1, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 1, 1, 1, 1], [1, 1, 0, 1, 0, 0, 1], [1, 1, 0, 1, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]], 'D': [[1, 1, 1, 0.75, 0.15], [1, 0, 0.15, 0.75, 0.75], [1, 0, 0, 0.15, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0.15, 1], [1, 0, 0.15, 0.75, 0.75], [1, 1, 1, 0.75, 0.15], [0, 0, 0, 0, 0]], 'H': [[1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0]], 'L': [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]], 'P': [[1, 1, 1, 1, 0.15], [1, 0, 0, 0.15, 1], [1, 0, 0, 0.15, 1], [1, 1, 1, 1, 0.15], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 0, 0, 0, 0]], 'T': [[1, 1, 1, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]], 'X': [[0.15, 0.75, 0, 0, 0.75, 0.15], [0, 0.75, 0.15, 0.15, 0.75, 0], [0, 0.15, 1, 0.75, 0.15, 0], [0, 0, 0.75, 0.75, 0, 0], [0, 0.15, 0.75, 0.75, 0.15, 0], [0.15, 1, 0.15, 0.15, 0.75, 0], [0.75, 0.75, 0, 0, 0.75, 0.75], [0, 0, 0, 0, 0, 0]], '\\': [[1, 0.15, 0], [0.75, 0.15, 0], [0.15, 0.75, 0], [0.15, 0.75, 0], [0, 1, 0.15], [0, 0.75, 0.15], [0, 0.15, 0.75], [0, 0, 0]], 'd': [[0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0.15, 1, 1, 0.75, 1], [1, 0.75, 0.15, 0.75, 1], [1, 0.15, 0, 0.15, 1], [1, 0.75, 0.15, 0.75, 1], [0.15, 1, 1, 0.75, 1], [0, 0, 0, 0, 0]], 'h': [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0.75, 1, 0.75], [1, 0.15, 0.15, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [0, 0, 0, 0]], 'l': [[1], [1], [1], [1], [1], [1], [1], [0]], 'p': [[0, 0, 0, 0], [0, 0, 0, 0], [1, 0.75, 1, 0.15], [1, 0.15, 0.15, 1], [1, 0, 0, 1], [1, 0.15, 0.15, 1], [1, 0.75, 1, 0.15], [1, 0, 0, 0]], 't': [[0, 0, 0], [0, 1, 0], [1, 1, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0.15], [0, 1, 1], [0, 0, 0]], 'x': [[0, 0, 0, 0], [0, 0, 0, 0], [0.75, 0.15, 0.15, 0.75], [0, 0.75, 0.75, 0.15], [0, 0.75, 0.75, 0], [0.15, 0.75, 0.75, 0.15], [0.75, 0.15, 0.15, 0.75], [0, 0, 0, 0]], "'": [[1], [1], [0.15], [0], [0], [0], [0], [0]], '+': [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 1, 0], [1, 1, 1], [0, 1, 0], [0, 1, 0], [0, 0, 0]], '/': [[0, 0.15, 0.75], [0, 0.75, 0.15], [0, 1, 0.15], [0.15, 0.75, 0], [0.15, 0.75, 0], [0.75, 0.15, 0], [1, 0.15, 0], [0, 0, 0]], '3': [[0.15, 1, 1, 1, 0.15], [1, 0.15, 0, 0.15, 1], [0, 0, 0.15, 0.15, 1], [0, 0, 1, 1, 0.15], [0, 0, 0, 0.15, 1], [1, 0.15, 0, 0.15, 1], [0.15, 1, 1, 1, 0.15], [0, 0, 0, 0, 0]], '7': [[1, 1, 1, 1], [0, 0, 0.15, 0.75], [0, 0, 0.75, 0.15], [0, 0.15, 0.75, 0], [0, 0.15, 0.75, 0], [0, 0.75, 0.15, 0], [0, 1, 0.15, 0], [0, 0, 0, 0]], ';': [[0], [0], [1], [0], [0], [0], [1], [1]], '?': [[0.75, 1, 1, 0.15], [1, 0.15, 0.15, 1], [0, 0, 0.15, 1], [0, 0.15, 1, 0.15], [0, 1, 0.15, 0], [0, 0.15, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0]], 'C': [[0, 0.75, 1, 1, 0.75, 0.15], [0.75, 0.75, 0.15, 0.15, 0.15, 1], [1, 0.15, 0, 0, 0, 0], [1, 0.15, 0, 0, 0, 0], [1, 0.15, 0, 0, 0, 0], [0.75, 0.75, 0.15, 0, 0.15, 1], [0, 0.75, 1, 1, 0.75, 0.15], [0, 0, 0, 0, 0, 0]], 'G': [[0, 0.75, 1, 1, 1, 0.75, 0.15], [0.75, 1, 0.15, 0.15, 0.15, 0.75, 0.75], [1, 0.15, 0, 0, 0, 0, 0], [1, 0.15, 0, 0, 1, 1, 1], [1, 0.15, 0, 0, 0, 0.15, 1], [0.15, 1, 0.15, 0.15, 0.15, 0.75, 1], [0, 0.15, 1, 1, 1, 0.15, 1], [0, 0, 0, 0, 0, 0, 0]], 'K': [[1, 0, 0, 0.15, 0.75, 0.15], [1, 0, 0.15, 1, 0.15, 0], [1, 0.15, 1, 0.15, 0, 0], [1, 0.75, 1, 0.15, 0, 0], [1, 0.15, 0.15, 0.75, 0, 0], [1, 0, 0, 0.75, 0.15, 0], [1, 0, 0, 0.15, 1, 0.15], [0, 0, 0, 0, 0, 0]], 'O': [[0, 0.15, 1, 1, 1, 0.15, 0], [0.15, 1, 0.15, 0.15, 0.15, 1, 0.15], [1, 0.15, 0, 0, 0, 0.15, 1], [1, 0.15, 0, 0, 0, 0.15, 1], [1, 0.15, 0, 0, 0, 0.15, 1], [0.15, 1, 0.15, 0.15, 0.15, 1, 0.15], [0, 0.15, 1, 1, 1, 0.15, 0], [0, 0, 0, 0, 0, 0, 0]], 'S': [[0.15, 1, 1, 1, 0.15], [1, 0.15, 0, 0.15, 1], [1, 0.15, 0, 0, 0], [0.15, 1, 0.75, 0.75, 0.15], [0, 0, 0.15, 0.75, 1], [1, 0.15, 0, 0.15, 1], [0.15, 1, 1, 1, 0.15], [0, 0, 0, 0, 0]], 'W': [[1, 0.15, 0, 0.15, 0.75, 0, 0, 0.75], [0.75, 0.15, 0, 0.75, 1, 0.15, 0, 1], [0.15, 0.75, 0, 1, 0.75, 0.15, 0.15, 1], [0.15, 0.75, 0.15, 0.75, 0.15, 0.75, 0.15, 0.75], [0, 1, 0.75, 0.75, 0, 1, 0.75, 0.15], [0, 0.75, 1, 0.15, 0, 0.75, 1, 0.15], [0, 0.75, 1, 0, 0, 0.75, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0]], '[': [[1, 0.75], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0]], '_': [[], [], [], [], [], [], [], []], 'c': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.15, 0.75, 1, 1, 0.15], [0.75, 0.75, 0.15, 0.15, 1], [1, 0.15, 0, 0, 0], [1, 0.75, 0.15, 0.15, 1], [0.15, 0.75, 1, 1, 0.15], [0, 0, 0, 0, 0]], 'g': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.15, 1, 1, 0.75, 1], [1, 0.15, 0.15, 0.75, 1], [1, 0.15, 0, 0.15, 1], [1, 0.15, 0.15, 0.75, 1], [0.15, 1, 1, 0.75, 1], [1, 0.15, 0.15, 0.75, 1]], 'k': [[1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0.75, 0.75, 0], [1, 0.75, 0.75, 0, 0], [1, 0.75, 0.75, 0, 0], [1, 0, 0.75, 0.15, 0], [1, 0, 0.15, 1, 0.15], [0, 0, 0, 0, 0]], 'o': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.15, 0.75, 1, 1, 0.15], [0.75, 0.75, 0.15, 0.75, 1], [1, 0.15, 0, 0.15, 1], [0.75, 0.75, 0.15, 0.75, 1], [0.15, 0.75, 1, 1, 0.15], [0, 0, 0, 0, 0]], 's': [[0, 0, 0, 0], [0, 0, 0, 0], [0.15, 1, 1, 0.15], [1, 0.15, 0.15, 1], [0.75, 1, 0.75, 0.15], [1, 0.15, 0.15, 1], [0.15, 1, 1, 0.75], [0, 0, 0, 0]], 'w': [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [1, 0, 0.15, 1, 0, 0.75, 0.75], [0.75, 0.15, 0.75, 1, 0.15, 0.75, 0.15], [0.15, 0.75, 1, 0.75, 0.15, 0.75, 0], [0.15, 0.75, 1, 0.15, 1, 0.75, 0], [0, 0.75, 0.75, 0, 1, 0.15, 0], [0, 0, 0, 0, 0, 0, 0]], '{': [[0, 0.75, 1], [0, 1, 0.15], [0, 1, 0], [0.15, 1, 0], [0.75, 0.75, 0], [0.15, 1, 0], [0, 1, 0], [0, 1, 0.15]], '"': [[1, 1], [1, 1], [0.15, 0.15], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], '&': [[0, 0.15, 1, 0.15, 0, 0], [0, 1, 0.15, 1, 0, 0], [0, 0.75, 0.75, 0.75, 0, 0], [0.15, 0.75, 0.75, 0.15, 0.15, 0], [1, 0.15, 0.15, 1, 0.75, 0], [1, 0.15, 0.15, 1, 0.75, 0], [0.15, 1, 1, 0.15, 0.75, 0.15], [0, 0, 0, 0, 0, 0]], '*': [[0.15, 1, 0.15], [0.75, 1, 0.75], [0.15, 0.15, 0.15], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], '.': [[0], [0], [0], [0], [0], [0], [1], [0]], '2': [[0.15, 1, 1, 1, 0.15], [1, 0.15, 0.15, 0.15, 1], [0, 0, 0, 0.15, 1], [0, 0, 0.15, 1, 0.15], [0, 0.15, 0.75, 0.15, 0], [0, 0.15, 0, 0, 0], [0, 1, 1, 1, 1], [0, 0, 0, 0, 0]], '6': [[0, 0.75, 1, 1, 0.15], [0.75, 0.75, 0.15, 0.75, 0.75], [1, 0.15, 0, 0, 0], [1, 0.75, 1, 1, 0.15], [1, 0.15, 0, 0.15, 1], [0.75, 0.15, 0, 0.15, 1], [0.15, 1, 1, 1, 0.15], [0, 0, 0, 0, 0]], ':': [[0], [0], [1], [0], [0], [0], [1], [0]], '>': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.15, 0, 0, 0, 0], [0.15, 0.75, 0.75, 0.15, 0], [0, 0, 0.15, 0.75, 0.75], [0, 0.15, 0.75, 0.75, 0.15], [0.15, 0.75, 0.15, 0, 0], [0, 0, 0, 0, 0]], 'B': [[1, 1, 1, 1, 0.15], [1, 0, 0, 0.15, 1], [1, 0, 0, 0.15, 1], [1, 1, 1, 1, 0.15], [1, 0, 0, 0.15, 1], [1, 0, 0, 0.15, 1], [1, 1, 1, 1, 0.15], [0, 0, 0, 0, 0]], 'F': [[1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0]], 'J': [[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [1, 0.15, 0.15, 1], [0.75, 1, 1, 0.15], [0, 0, 0, 0]], 'N': [[1, 0.15, 0, 0, 1], [1, 0.75, 0, 0, 1], [1, 0.75, 0.15, 0, 1], [1, 0, 0.75, 0, 1], [1, 0, 0.15, 0.15, 1], [1, 0, 0, 0.75, 1], [1, 0, 0, 0.15, 1], [0, 0, 0, 0, 0]], 'R': [[1, 1, 1, 1, 0.15, 0], [1, 0, 0, 0.15, 1, 0], [1, 0, 0, 0.15, 1, 0], [1, 1, 1, 1, 0.15, 0], [1, 0, 0, 0.15, 1, 0], [1, 0, 0, 0, 1, 0], [1, 0, 0, 0, 1, 0.75], [0, 0, 0, 0, 0, 0]], 'V': [[0.75, 0.15, 0, 0, 0.15, 0.75], [0.15, 0.75, 0, 0, 0.75, 0.15], [0.15, 1, 0, 0.15, 1, 0], [0, 0.75, 0.15, 0.15, 0.75, 0], [0, 0.15, 0.75, 0.75, 0.15, 0], [0, 0.15, 1, 0.75, 0, 0], [0, 0, 0.75, 0.75, 0, 0], [0, 0, 0, 0, 0, 0]], 'Z': [[0.75, 1, 1, 1, 1, 0.15], [0, 0, 0, 0.15, 1, 0.15], [0, 0, 0.15, 1, 0.15, 0], [0, 0, 0.75, 0.15, 0, 0], [0, 0.75, 0.75, 0, 0, 0], [0.15, 0.75, 0, 0, 0, 0], [0.75, 1, 1, 1, 1, 0.15], [0, 0, 0, 0, 0, 0]], '^': [[0, 0.75, 0.75, 0], [0, 0.75, 0.75, 0.15], [0.15, 0.15, 0.15, 0.75], [0.15, 0.15, 0, 0.15], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], 'b': [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0.75, 1, 0.15], [1, 0.15, 0.15, 1], [1, 0, 0, 1], [1, 0.15, 0.15, 1], [1, 0.75, 1, 0.15], [0, 0, 0, 0]], 'f': [[0, 0.75, 1], [0, 1, 0.15], [1, 1, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 0, 0]], 'j': [[0, 1], [0, 0], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0.15, 1]], 'n': [[0, 0, 0, 0], [0, 0, 0, 0], [1, 0.75, 1, 0.75], [1, 0.15, 0.15, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [0, 0, 0, 0]], 'r': [[0, 0, 0], [0, 0, 0], [1, 0.75, 0.75], [1, 0.15, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [0, 0, 0]], 'v': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.75, 0.15, 0, 0.75, 0.15], [0.75, 0.15, 0, 0.75, 0], [0.15, 0.75, 0.15, 0.75, 0], [0, 0.75, 0.75, 0.15, 0], [0, 0.75, 0.75, 0, 0], [0, 0, 0, 0, 0]], 'z': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.75, 1, 1, 1, 0], [0, 0, 0.15, 0.75, 0], [0, 0.15, 0.75, 0, 0], [0.15, 0.75, 0, 0, 0], [0.75, 1, 1, 1, 0.15], [0, 0, 0, 0, 0]], '~': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.75, 1, 0.75, 0.15, 1], [1, 0.15, 0.75, 1, 0.75], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], '!': [[1], [1], [1], [1], [0.75], [0.15], [1], [0]], '%': [[0.15, 1, 1, 0.15, 0, 0.15, 0.15, 0], [1, 0.15, 0.15, 1, 0, 0.15, 0, 0], [1, 0.15, 0.15, 1, 0.15, 0.15, 0, 0], [0.15, 1, 1, 0.15, 0.75, 0, 0, 0], [0, 0, 0, 0.75, 0.15, 0.75, 1, 0.75], [0, 0, 0.15, 0.75, 0, 1, 0.15, 1], [0, 0, 0.75, 0.15, 0, 0.75, 1, 0.75], [0, 0, 0, 0, 0, 0, 0, 0]], ')': [[0.15, 0.75, 0], [0, 0.75, 0.15], [0, 0.15, 0.75], [0, 0.15, 1], [0, 0, 1], [0, 0.15, 1], [0, 0.15, 0.75], [0, 0.75, 0]], '-': [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [1, 1, 0.15], [0, 0, 0], [0, 0, 0], [0, 0, 0]], '1': [[0.15, 1], [1, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 0]], '5': [[0.15, 1, 1, 1, 0.75], [0.15, 0.75, 0, 0, 0], [0.15, 0.75, 1, 1, 0.15], [0.75, 0.75, 0.15, 0.75, 1], [0, 0, 0, 0.15, 1], [1, 0.75, 0.15, 0.75, 0.75], [0.15, 1, 1, 0.75, 0.15], [0, 0, 0, 0, 0]], '9': [[0.15, 0.75, 1, 0.75, 0.15], [0.75, 0.75, 0.15, 0.75, 0.75], [1, 0.15, 0, 0.15, 1], [1, 0.75, 0.15, 0.75, 1], [0.15, 1, 1, 0.75, 1], [0.75, 0.75, 0.15, 0.75, 0.75], [0.15, 1, 1, 0.75, 0.15], [0, 0, 0, 0, 0]], '=': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.75, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0.75, 1, 1, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], 'A': [[0, 0, 0.75, 0.75, 0, 0], [0, 0.15, 0.75, 1, 0.15, 0], [0, 0.15, 0.75, 0.75, 0.15, 0], [0, 0.75, 0.15, 0.15, 0.75, 0], [0.15, 1, 1, 1, 1, 0.15], [0.15, 0.75, 0, 0, 0.75, 0.15], [0.75, 0.15, 0, 0, 0.15, 0.75], [0, 0, 0, 0, 0, 0]], 'E': [[1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]], 'I': [[1], [1], [1], [1], [1], [1], [1], [0]], 'M': [[1, 0.75, 0, 0, 0.75, 1], [1, 0.75, 0, 0, 0.75, 1], [1, 0.75, 0.15, 0.15, 0.75, 1], [1, 0.15, 0.15, 0.15, 0.15, 1], [1, 0.15, 0.75, 0.75, 0.15, 1], [1, 0, 0.75, 0.75, 0, 1], [1, 0, 0.75, 0.75, 0, 1], [0, 0, 0, 0, 0, 0]], 'Q': [[0, 0.15, 1, 1, 1, 0.15, 0], [0.15, 1, 0.15, 0.15, 0.15, 1, 0.15], [1, 0.15, 0, 0, 0, 0.15, 1], [1, 0.15, 0, 0, 0, 0.15, 1], [1, 0.15, 0, 0, 0.15, 0.15, 1], [0.15, 1, 0.15, 0.15, 0.75, 1, 0.15], [0, 0.15, 1, 1, 1, 0.75, 0.75], [0, 0, 0, 0, 0, 0, 0.15]], 'U': [[1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0.15, 0.15, 0.15, 1], [0.15, 1, 1, 1, 0.15], [0, 0, 0, 0, 0]], 'Y': [[0.15, 1, 0, 0, 0, 1, 0.15], [0, 0.75, 0.15, 0, 0.15, 0.75, 0], [0, 0.15, 1, 0.15, 1, 0.15, 0], [0, 0, 0.75, 1, 0.75, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]], ']': [[1, 0.75], [0, 0.75], [0, 0.75], [0, 0.75], [0, 0.75], [0, 0.75], [0, 0.75], [0, 0.75]], 'a': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.15, 1, 1, 0.75, 0], [1, 0.15, 0.15, 1, 0], [0.15, 0.75, 0.75, 1, 0], [1, 0.75, 0.75, 1, 0.15], [0.75, 1, 0.75, 0.75, 0.75], [0, 0, 0, 0, 0]], 'e': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.15, 0.75, 1, 1, 0.15], [0.75, 0.15, 0.15, 0.15, 0.75], [1, 1, 1, 1, 1], [0.75, 0.15, 0.15, 0.75, 0.75], [0.15, 0.75, 1, 0.75, 0.15], [0, 0, 0, 0, 0]], 'i': [[1], [0], [1], [1], [1], [1], [1], [0]], 'm': [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0.75, 0.75, 0.75, 1, 0.75], [1, 0.15, 1, 0.15, 0.15, 1], [1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 0, 1], [1, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0]], 'q': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.15, 1, 1, 0.75, 1], [0.75, 0.75, 0.15, 0.75, 1], [1, 0.15, 0, 0.15, 1], [1, 0.75, 0.15, 0.75, 1], [0.15, 1, 1, 0.75, 1], [0, 0, 0, 0, 1]], 'u': [[0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 0.15, 0.15, 1], [0.75, 1, 0.75, 1], [0, 0, 0, 0]], 'y': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0.75, 0.15, 0, 0.75, 0.15], [0.75, 0.75, 0, 0.75, 0], [0.15, 0.75, 0.15, 0.75, 0], [0, 0.75, 0.75, 0.15, 0], [0, 0.15, 1, 0, 0], [0, 0.75, 0.75, 0, 0]], '}': [[1, 0.75, 0], [0.15, 1, 0], [0, 1, 0], [0, 1, 0.15], [0, 0.75, 0.75], [0, 1, 0.15], [0, 1, 0], [0.15, 1, 0]]} # paste font dictionary here if len(sys.argv) > 1: args = sys.argv del args[0] string_to_show = ' '.join(args) scroll_rows=[[0]*8]*8 # blank space at start of message for character in string_to_show: if character in font_dictionary: character_rows = font_dictionary[character] else: character_rows = font_dictionary['-'] for i in range(8): scroll_rows[i] = scroll_rows[i]+character_rows[i] scroll_rows[i] += [0] # gap between letters for i in range(8): scroll_rows[i]+=[0]*8 # blank space at end of message for scroll_position in range(len(scroll_rows[0])-8):
import copy, random import colorsys import time nohat = 0 try: import unicornhat as uh except ImportError: print "no Unicornhat found" nohat = 1 import time if not nohat: uh.brightness(.2) def show_matrix(mat): for row in mat: print " ".join(str(x[0]) for x in row) def uh_show_matrix(mat, pause = .075): for y in range(len(mat)): for x in range(len(mat[0])): uh.set_pixel(x, y, mat[x][y][0], mat[x][y][1], mat[x][y][2]) uh.show() time.sleep(pause) def pomodoro(color = (255,0,0), min=25): for y in range(8): for x in range(8): uh.set_pixel(x, y, color[0], color[1], color[2])
# See the License for the specific language governing permissions and # limitations under the License. # # Import library functions we need import sys import os import unicornhat as UH if sys.version_info >= (3, 0): print("Sorry - currently only configured to work with python 2.x") sys.exit(1) brightness = float(sys.argv[1]) / 100 UH.off() UH.brightness(brightness) while True: try: data = raw_input() if len(data) < 10: if data[0] == "B": UH.brightness(float(data[1:]) / 100) if data[0] == "R": UH.rotation(float(data[1:])) else: if data[0] == "P": data = data[1:].strip() s = data.split(',') for p in range(0, len(s), 5): UH.set_pixel(int(s[p]), int(s[p + 1]), int(s[p + 2]),
else: print 'The market is up', numfloat, 'percent.' print "" #optional delay #time.sleep(2) #unicorn hat matrix color change based on market direction import unicornhat as unicorn from random import randint import time #tie LED brightness to change magnitude here unicorn.brightness(0.30) unicorn.rotation(90) #colors if market is up, down,or zero change if numfloat > 0: wrd_rgb = [[154, 173, 154], [0, 255, 0], [0, 200, 0], [0, 162, 0], [0, 145, 0], [0, 96, 0], [0, 74, 0], [0, 0, 0,]] elif numfloat == 0: wrd_rgb = [[255, 20, 20], [245, 10, 10], [200, 0, 10], [162, 0, 0], [145, 0, 0], [96, 0, 0], [74, 0, 0], [0, 0, 0,]] else: #maybe change this to rainbow sparkles wrd_rgb = [[255, 255, 154], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0], [255, 255, 0,]] clock = 0 blue_pilled_population = [[randint(0,7), 7]] #while True:
#!/usr/bin/env python import datetime import time import unicornhat as unicorn from random import randint unicorn.set_layout(unicorn.PHAT) unicorn.brightness(0.3) unicorn.clear() def blank(): x = randint(0, 7) y = randint(0, 3) r = 0 g = 0 b = 0 unicorn.set_pixel(x, y, r , g, b) unicorn.show() #random patterns def random(): x = randint(0, 7) y = randint(0, 3) r = randint(1, 255) g = randint(1, 255) b = randint(1, 255) unicorn.set_pixel(x, y, r , g, b) unicorn.show()
#!/usr/bin/env python ################################################################ # Pibow Candy Rainbow # ################################################################ # Description: # # This is a modification of my Moving Rainbow program. I just # # changed the colors to pastels to match the Pibow Candy case. # # # # Author: Paul Ryan # # # ################################################################ import unicornhat, signal, time, random unicornhat.set_layout(unicornhat.PHAT) unicornhat.brightness(0.5) unicornhat.rotation(180) def pibow_candy_rainbow(): R = (255, 105, 97) O = (255, 179, 71) Y = (253, 253, 150) G = (119, 190, 119) B = (119, 158, 203) I = (150, 111, 214) V = (203, 153, 201) W = (244, 154, 194) off = (0, 0, 0) rainbow0 = [ [R, O, Y, G, B, I, V, W],
def reset_leds(): global width, height unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) unicorn.brightness(1.0) width, height = unicorn.get_shape()
# Import the libraries for the Unicorn HAT. # The "as" keyword means to import the Unicorn HAT package as the variable "unicorn" import unicornhat as unicorn # Setting up the Unicorn HAT # NOTE: If only half of the screen lights up, changes "unicorn.AUTO" to "unicorn.HAT" unicorn.set_layout(unicorn.AUTO) # This sets the rotation of the LED's. We shouldn't need to change this much, but try setting it to 90, 180, -90, or -180. unicorn.rotation(0) # This sets the brightness of the LED lights, from 0.0 to 1.0 MAX. unicorn.brightness(0.5) # This sets two variables at once -- "width" and "height" -- to the same value. In this case, the value of "get_shape". # Don't worry too much about what "get_shape()" does. It comes from "unicorn", which is our Unicorn HAT package. # Someone else wrote this code so we don't have to! width, height = unicorn.get_shape() # So! Near the top of every script, you should have something like this: import unicornhat as unicorn unicorn.set_layout(unicorn.AUTO) unicorn.rotation(0) unicorn.brightness(0.5) width, height = unicorn.get_shape() # Let's turn the LED at the top-left corner on. This corner has the coordinates of x=0 and y=x. # The "unicorn.set_pixel" command helps us set a pixel to be a certain color. It takes 5 arguments in this order: # set_pixel(x,y,r,g,b) # Where x is the x-axis; y is the y-axis; and r, g, and b represent "red", "green", and "blue" - the 3 colors in every pixel.
def setAllPixels(r, g, b, brightness): uh.brightness(brightness) for x in range(8): for y in range(8): uh.set_pixel(x, y, r, g, b) uh.show()
import unicornhat as unicorn print("""Figlet You should see scrolling text that is defined in the TXT variable. If the text moves in the wrong direction, change the rotation from 0 to 180. Text output is kind of limited on a pHAT of course because most letters don't fit on the small display of 4x8. """) unicorn.set_layout(unicorn.HAT) unicorn.rotation(0) unicorn.brightness(1.0) #unicorn.brightness(0.5) width, height = unicorn.get_shape() TXT = "HELLO" figletText = figlet_format( TXT + ' ', "banner", width=1000) # banner font generates text with heigth 7 textMatrix = figletText.split( "\n")[:width] # width should be 8 on both HAT and pHAT! textWidth = len(textMatrix[0]) # the total length of the result from figlet i = -1 def step():
def snow_wrapper(end_time, r, g, b, brightness): logging.info("showing snow") uh.brightness(brightness) snow.snow(end_time)