Skip to content
Snippets Groups Projects
Commit ccf00777 authored by ed8g20's avatar ed8g20
Browse files

Upload New File

parent d776d1b2
No related branches found
No related tags found
No related merge requests found
main.py 0 → 100644
import time
import json
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_RGB332
from pimoroni import Button
from totp import totp
from synchronised_time import create_synchronised_time
LED_BLINK_UNDER_SECONDS = 6
display = PicoGraphics(display = DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB332, rotate = 0)
display.set_font("bitmap8")
WHITE = display.create_pen(255, 255, 255)
BLACK = display.create_pen(0, 0, 0)
button_a = Button(12)
button_b = Button(13)
button_x = Button(14)
button_y = Button(15)
display_width, display_height = display.get_bounds()
def hex_to_rgb(hex):
return tuple(int(hex[i:i+2], 16) for i in (1, 3, 5))
codes = json.loads(open("codes.json", "r").read())
selected_idx = 0
synchronised_time = create_synchronised_time(display, button_a, button_b, button_x, button_y)
while True:
if button_a.read() :
selected_idx = (selected_idx + 1) % len(codes)
code = codes[selected_idx]
(password, expiry) = totp(synchronised_time(),
code['key'],
step_secs=code['step'],
digits=code['digits'])
colour = hex_to_rgb(code['colour'])
display.set_pen(display.create_pen(*colour))
display.clear()
display.set_pen(BLACK)
display.text(code['name'], 10, 10, display_width - 10, 4)
display.text(password, 10, 60, display_width - 10, 6)
progress_width = display_width - \
(display_width // code['step'] * (expiry - 1))
display.rectangle(0, 125, progress_width, 10)
display.update()
time.sleep(0.5)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment