def lcd(data): if data["command"] == "write": lcd.write(data["value"]) return True if data["command"] == "clear": lcd.clear() return True if data["command"] == "set_contrast": lcd.set_contrast(data["contrast"]) return True if data["command"] == "set_cursor_position": lcd.set_cursor_position(data["column"], data["row"]) return True if data["command"] == "set_cursor_offset": lcd.set_cursor_offset(data["offset"]) return True if data["command"] == "set_display_mode": lcd.set_display_mode(data["enable"], data["cursor"], data["blink"]) return True if data["command"] == "create_char": lcd.create_char(data["char_pos"], data["char_map"]) return True if data["command"] == "create_animation": lcd.create_animation(data["anim_pos"], data["anim_map"], data["frame_rate"]) return True if data["command"] == "update_animations": lcd.update_animations() return True
def init_display(): backlight.graph_set_led_duty(0, 1) if flipped: for i in range(len(SPECTRUM_CHARS_FLIP)): lcd.create_char(i, SPECTRUM_CHARS_FLIP[i]) else: for i in range(len(SPECTRUM_CHARS)): lcd.create_char(i, SPECTRUM_CHARS[i])
return char[int(round(time.time() * fps) % len(char))] x = 0 text = " pimoroni ftw " while True: x += 3 x %= 360 backlight.sweep((360.0 - x) / 360.0) backlight.set_graph(abs(math.sin(x / 100.0))) if x == 0: lcd.set_cursor_position(0, 1) lcd.write(" " * 16) pos = int(x / 20) lcd.set_cursor_position(0, 1) lcd.write(text[:pos] + "\x02") lcd.set_cursor_position(0, 2) lcd.write(colours[int(x / 52)]) lcd.create_char(0, get_anim_frame(pirate, 2)) lcd.create_char(1, get_anim_frame(heart, 2)) lcd.create_char(2, get_anim_frame(pacman, 2)) time.sleep(0.01)
def setup_icons(self): lcd.create_char(0, self.icon_record) lcd.create_char(1, MenuIcon.pause) lcd.create_char(2, self.icon_stop)
[0,0,0,0,0,0,0,0] ] def tidyup(): backlight.off() lcd.clear() def get_anim_frame(char,fps): return char[ int(round(time.time()*fps) % len(char)) ] backlight.graph_off() backlight.off() lcd.set_cursor_position(0,0) lcd.write(chr(0) * 16) lcd.set_cursor_position(0,1) lcd.write(chr(0) * 16) lcd.set_cursor_position(0,2) lcd.write(chr(0) * 16) time.sleep(1) for x in range(0,255,5): backlight.single_rgb(3,x,x,x) atexit.register(tidyup) while True: lcd.create_char(0,get_anim_frame(rain,20)) time.sleep(0.1) #signal.pause()
def redraw(self, menu): """ The output to the LCD looks as follows |Mon 01 Jan 16:35| |Mon 01 Jan 16.35| |[1] Now 0d7h25m | |[1] In 04d5h25m | |Event descriptio| |Event descriptio| Line 1: constantly updating clock. Time seperator blinks between : and . Line 2: Event number in square brackets Ongoing events show "Now", an arrow and time to end of event. Upcoming events show "In", and a countdown to start of event. Line 3: Event description. "All Day:" is appended if it's an all day event. Will scroll if the line doesn't fully fit on the screen. """ # Start by seeing if we need to be in a reminder state reminderactive=0 for reminder in self.reminders: timenow=datetime.datetime.now(self.localtz) if (timenow > reminder['start'] and timenow < reminder['end']): reminderactive=1 # Decide what to do with the graph LEDs and set them graphstates = self.CalculateGraph(reminderactive) for x in range(6): backlight.graph_set_led_state(x,graphstates[x]) # If it's time for a refresh because an event's ended, do a background refresh if (datetime.datetime.now(self.localtz) > self.nextrefresh): thread.start_new_thread(self.BgUpdateCalendar,()) return # If maxevents is zero, we have no events due to an error or an empty calendar if (self.maxevents == 0): menu.write_option( row=0, text="No events!", scroll=False ) menu.write_option( row=1, text="Rechecking at", scroll=False ) menu.write_option( row=2, text=str(self.nextrefresh.time().replace(microsecond=0)), scroll=False ) return # If there's a calendar update happening, say so and do nothing else. # Don't update if the screensave is active.. if (self.updating_calendar == 1 and self.screensave==0): menu.write_option( row=0, text="Please Wait", scroll=False ) menu.write_option( row=1, text="Updating", scroll=False ) menu.write_option( row=2, text="Calendar", scroll=False ) return # Do nothing if the screen is turned off if (self.screensave == 1): return # If the idle timer has been reached, turn the screen off if ((time.time() - self.idletimer) > self.idletimeout): lcd.clear() self.screensave = 1 backlight.rgb(0,0,0) return # A screensave state of 2 means we need to activate the screen/ # Restore the backlight to the last saved RGB values. if (self.screensave == 2): backlight.rgb(self.red,self.green,self.blue) # Either the displayed event has been changed, or the time has moved on a minute # In both cases, we need to recalculate the countdown strings if ((self.d_event != self.c_event) or (datetime.datetime.now().minute != self.last_update)): # Create timediff items so we can see when the start and finish are relative to now self.timetoevent=self.events[self.d_event]['estart_dt'] - datetime.datetime.now(self.localtz) self.timetoend=self.events[self.d_event]['eend_dt'] - datetime.datetime.now(self.localtz) # Calculate days/hours/mins remaining till event start self.tte_days = self.timetoevent.days self.tte_secs = self.timetoevent.seconds self.tte_hours = (self.tte_secs // 3600) # +1 minute because we're not counting seconds self.tte_mins = ((self.tte_secs % 3600) // 60) + 1 # Though this does introduce a kettle of worms that 1h60m is a possible result. if (self.tte_mins == 60): self.tte_hours = self.tte_hours + 1 self.tte_mins = 0 # Calculate days/hours/mins remaining till event finish self.ttee_days = self.timetoend.days self.ttee_secs = self.timetoend.seconds self.ttee_hours = (self.ttee_secs // 3600) # +1 minute because we're not counting seconds self.ttee_mins = ((self.ttee_secs % 3600) // 60) + 1 # Though this does introduce a kettle of worms that 1h60m is a possible result. if (self.ttee_mins == 60): self.ttee_hours = self.ttee_hours + 1 self.ttee_mins = 0 # Update state to reflect the event and the timestamp we've calculated for self.c_event = self.d_event self.last_update = datetime.datetime.now().minute # If the number of days to the event is positive, the event is upcoming. # Work out how long we have till the event starts. # If it's negative, the event has already started, so instead we work out how long till the end if (self.tte_days >= 0): # If it's over a week away, just show days remaining if (self.tte_days > 7): countdown = ("[" + str(self.d_event+1) + "] in " + str(self.tte_days) + "d" ) else: countdown=("[" + str(self.d_event+1) + "] in " + str(self.tte_days) + "d" + str(self.tte_hours) + "h" + str(self.tte_mins) + "m" ) start = self.events[self.d_event]['estart_dt'].astimezone(self.localtz).strftime("%H:%M") else: # Recreate the arrow character when we know we need to use it. Just to be safe. # Just show days if it's not finishing in less than a week :) lcd.create_char(1, self.arrow) if (self.ttee_days > 7): countdown= "["+ str(self.d_event+1) + "] Now\x01" + str(self.ttee_days) + "d" else: countdown= ("["+ str(self.d_event+1) + "] Now\x01" + str(self.ttee_days) + "d" + str(self.ttee_hours) + "h" + str(self.ttee_mins) + "m" ) start = "" # If the event is less than 300 minutes away (5 hours), vary the backlight # Hue values 0.0 -> 0.3 give us a decent green -> red transition. # Take the number of seconds left, divide by 60 to give us minutes remaining # then divide by 1,000 to give us 0.3 at 300 mins left ~~> 0.0 at 0 mins. # Use the provided hue_to_rgb() function to do the maths for us, and set the # backlight accordingly. if (self.tte_days == 0 and (float(self.tte_secs) / 60) < 300): rgb = backlight.hue_to_rgb(float(self.tte_secs)/60000) self.SetRGB(rgb[0], rgb[1], rgb[2]) else: self.SetRGB(self.defaultR, self.defaultG, self.defaultB) # Pick out the event summary if (self.events[self.d_event]['allday_flag'] == True): summary = "All Day:" + self.events[self.d_event]['summary'] else: summary = start + " " + self.events[self.d_event]['summary'] # We don't need to bother scrolling events with short names if (len(summary) < 16): scrollsummary = False else: scrollsummary = True # When the clock's active, we use a custom character for the colon # We redefine this character every other second so the top dot is # missing. Which gives us a nice 'blinking' top dot in the time :) animframe = (datetime.datetime.now().second % 2) lcd.create_char(2, self.clockanim[animframe]) # datetime.now returns local time, so this behaves correctly clockstring=datetime.datetime.now(self.localtz).strftime('%a %d %b %H\x02%M') # Write the menu rows menu.write_option( row=0, text=clockstring, scroll=False ) menu.write_option( row=1, text=countdown, scroll=False ) menu.write_option( row=2, text=summary, scroll=scrollsummary )
'name': 'Magenta', 'combo': (255, 0, 255) }, { 'name': 'Aqua', 'combo': (0, 255, 255) }, { 'name': 'Purple', 'combo': (131, 66, 244) }, { 'name': 'Indiglo', 'combo': (0, 66, 33) }] lcd.set_contrast(51) lcd.create_char(0, [0, 14, 10, 10, 10, 10, 14, 0]) lcd.create_char(1, [0, 14, 14, 14, 14, 14, 14, 0]) months_abbr = [ None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] trailing_zeros = [ '00', '01', '02', '03', '04', '05', '06', '07',
sys.exit() elif command == 'reset': lcd.clear() backlight.off() backlight.graph_off() elif component == 'LCD': if command == 'clear': lcd.clear() elif command == 'setContrast': lcd.set_contrast(parameters['contrast']) elif command == 'setCursorPosition': lcd.set_cursor_position(parameters['column'], parameters['row']) elif command == 'write': lcd.write(parameters['value']) elif command == 'createCharacter': lcd.create_char(parameters['memoryPosition'], parameters['map']) elif command == 'writeCharacter': lcd.write(chr(parameters['memoryPosition'])) elif component == 'Backlight': if command == 'turnOff': backlight.off() elif command == 'setBrightnessOfLed': backlight.set(parameters['ledIndex'], parameters['brightness']) elif command == 'setToHue': backlight.hue(parameters['hue']) elif command == 'setLeftToHue': backlight.left_hue(parameters['hue']) elif command == 'setMiddleToHue': backlight.mid_hue(parameters['hue']) elif command == 'setRightToHue': backlight.right_hue(parameters['hue'])
raspberry x = 0 text = " pimoroni ftw " while True: x += 3 x %= 360 backlight.sweep((360.0 - x) / 360.0) backlight.set_graph(abs(math.sin(x / 100.0))) if x == 0: lcd.set_cursor_position(0, 1) lcd.write(" " * 16) pos = int(x / 20) lcd.set_cursor_position(0, 1) lcd.write(text[:pos] + "\x02") lcd.set_cursor_position(0, 2) lcd.write(colours[int(x / 52)]) lcd.create_char(0, getAnimFrame(pirate, 2)) lcd.create_char(1, getAnimFrame(heart, 2)) lcd.create_char(2, getAnimFrame(pacman, 2)) time.sleep(0.01)
def setup(): GPIO.setmode(GPIO.BCM) GPIO.setup(5, GPIO.IN) GPIO.setup(6, GPIO.IN) lcd.set_contrast(53) # Custom font sprites for drawing huge "GOAL" # full block lcd.create_char(0, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]) # bottom half block lcd.create_char(1, [0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]) # bottom right corner lcd.create_char(2, [0x01, 0x03, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x1f]) # top right corner lcd.create_char(3, [0x1f, 0x0f, 0x0f, 0x07, 0x07, 0x03, 0x03, 0x01]) # bottom left corner lcd.create_char(4, [0x10, 0x18, 0x18, 0x1c, 0x1c, 0x1e, 0x1e, 0x1f]) # top right corner lcd.create_char(5, [0x1f, 0x1e, 0x1e, 0x1c, 0x1c, 0x18, 0x18, 0x10]) # Top pyramid corner of A lcd.create_char(6, [0, 0, 0x04, 0x04, 0x0e, 0x0e, 0x1f, 0x1f]) global goals_locked goals_locked = True GPIO.add_event_detect(5, GPIO.RISING, callback=on_goal_1, bouncetime=3000) GPIO.add_event_detect(6, GPIO.RISING, callback=on_goal_2, bouncetime=3000)
0b00000, 0b00000, ] happy = [ 0b00000, 0b00000, 0b01010, 0b00000, 0b10001, 0b01110, 0b00000, 0b00000, ] # Set up the icons lcd.create_char(0, arrow) lcd.create_char(1, sad) lcd.create_char(2, ok) lcd.create_char(3, happy) # Set up the LCD display and show starting lcd.set_contrast(50) backlight_rgb(255, 0, 255) lcd.clear() lcd.set_cursor_position(0, 0) lcd.write("Starting...") # Wait the sensor to become ready while True: try: print("Trying to get sensor...")