Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from picoscroll import PicoScroll
- from picographics import PicoGraphics, DISPLAY_SCROLL_PACK, PEN_P8
- graphics = PicoGraphics(DISPLAY_SCROLL_PACK, pen_type=PEN_P8)
- scroll = PicoScroll()
- scroll_brightness = 32
- # Character pixel maps (3w x 5h font)
- chr_3x5_zero = [0,1,1,1,0],[1,0,0,0,1],[0,1,1,1,0]
- chr_3x5_one = [0,1,0,0,1],[1,1,1,1,1],[0,0,0,0,1]
- chr_3x5_two = [1,0,0,1,1],[1,0,1,0,1],[0,1,0,0,1]
- chr_3x5_three = [1,0,0,0,1],[1,0,1,0,1],[0,1,0,1,0]
- chr_3x5_four = [0,1,1,1,0],[1,0,0,1,0],[0,0,1,1,1]
- chr_3x5_five = [1,1,1,0,1],[1,0,1,0,1],[1,0,0,1,0]
- chr_3x5_six = [0,1,1,1,0],[1,0,1,0,1],[0,0,0,1,0]
- chr_3x5_seven = [1,0,0,1,1],[1,0,1,0,0],[1,1,0,0,0]
- chr_3x5_eight = [0,1,0,1,0],[1,0,1,0,1],[0,1,0,1,0]
- chr_3x5_nine = [0,1,0,0,0],[1,0,1,0,1],[0,1,1,1,0]
- chr_3x5_error = [1,1,1,1,1],[1,0,1,0,1],[1,0,1,0,1]
- chr_3x5_list = [chr_3x5_zero, chr_3x5_one, chr_3x5_two, chr_3x5_three, chr_3x5_four,
- chr_3x5_five, chr_3x5_six, chr_3x5_seven, chr_3x5_eight, chr_3x5_nine]
- # draw clock digit using above pixel map, left to right, top to bottom
- def draw_3x5_character(x, y, digit):
- if digit >= 0 and digit <=9:
- _chr = chr_3x5_list[digit]
- else:
- _chr = chr_3x5_error
- graphics.set_pen(scroll_brightness)
- for _hor in range(3):
- for _vert in range(5):
- if(_chr[_hor][_vert] == 1):
- graphics.pixel(x + _hor, y + _vert)
- def draw_clock():
- # save time to local list
- _time = time.localtime() # [0]=year, [1]=month, [2]=day, [3]=hour, [4]=minute, [5]=second
- # clear canvas
- graphics.set_pen(0)
- graphics.clear()
- # draw digits
- draw_3x5_character(0,0,_time[3] // 10) # hour tens (0-2)
- draw_3x5_character(4,0,_time[3] % 10) # hour units (0-9)
- draw_3x5_character(10,0,_time[4] // 10) # minute tens (0-5)
- draw_3x5_character(14,0,_time[4] % 10) # minute units (0-9)
- # draw colon between hours and minutes on odd seconds
- if(_time[5] % 2 != 0):
- graphics.set_pen(scroll_brightness)
- graphics.pixel(8,1)
- graphics.pixel(8,3)
- # seconds pixel bar across the bottom - borrowed from the scrollphathd clock example
- seconds_progress = 15 * ((_time[5] % 60) / 59.0)
- for y in range(15):
- current_pixel = min(seconds_progress, 1)
- graphics.set_pen(int(current_pixel * scroll_brightness))
- graphics.pixel(y + 1, 6)
- seconds_progress -= 1
- if seconds_progress <= 0:
- break
- # transfer canvas to display
- scroll.update(graphics)
- while True:
- draw_clock()
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement