From 90a2076b7b120cf87829cf6a26894b3d663d9aae Mon Sep 17 00:00:00 2001 From: Irvin Makosa Date: Wed, 2 Aug 2023 00:56:16 +0100 Subject: [PATCH] display percentage icon --- micropython/examples/galactic_unicorn/light_sensor.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/micropython/examples/galactic_unicorn/light_sensor.py b/micropython/examples/galactic_unicorn/light_sensor.py index 1b6759d6..8f1bbf1c 100644 --- a/micropython/examples/galactic_unicorn/light_sensor.py +++ b/micropython/examples/galactic_unicorn/light_sensor.py @@ -56,6 +56,13 @@ def calculate_brightness(current_lsv): return brightness_val +# draws percentage icon +def draw_percentage(x, y): + graphics.rectangle(x + 1, y + 1, 2, 2) + graphics.line(x, y + 6, x + 6, y) + graphics.rectangle(x + 4, y + 4, 2, 2) + + # sets up a handy function we can call to clear the screen def clear(): graphics.set_pen(BLACK) @@ -105,7 +112,8 @@ while True: graphics.text("BRT: ", 0, 1, scale=1) # measure the rest of the text before drawing to right align it text_width = graphics.measure_text(f"{bp:.0f}/°", scale=1) - graphics.text(f"{bp:.0f}%", WIDTH - text_width, 1, scale=1) + graphics.text(f"{bp:.0f}", WIDTH - text_width, 1, scale=1) + draw_percentage((WIDTH - text_width) + 10, 1) # draw a bar for the background graphics.set_pen(GREY) @@ -118,4 +126,3 @@ while True: # time to update the display gu.update(graphics) - # time.sleep(1)