Skip to content

Commit 90a2076

Browse files
committed
display percentage icon
1 parent e14903d commit 90a2076

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

micropython/examples/galactic_unicorn/light_sensor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def calculate_brightness(current_lsv):
5656
return brightness_val
5757

5858

59+
# draws percentage icon
60+
def draw_percentage(x, y):
61+
graphics.rectangle(x + 1, y + 1, 2, 2)
62+
graphics.line(x, y + 6, x + 6, y)
63+
graphics.rectangle(x + 4, y + 4, 2, 2)
64+
65+
5966
# sets up a handy function we can call to clear the screen
6067
def clear():
6168
graphics.set_pen(BLACK)
@@ -105,7 +112,8 @@ def clear():
105112
graphics.text("BRT: ", 0, 1, scale=1)
106113
# measure the rest of the text before drawing to right align it
107114
text_width = graphics.measure_text(f"{bp:.0f}/°", scale=1)
108-
graphics.text(f"{bp:.0f}%", WIDTH - text_width, 1, scale=1)
115+
graphics.text(f"{bp:.0f}", WIDTH - text_width, 1, scale=1)
116+
draw_percentage((WIDTH - text_width) + 10, 1)
109117

110118
# draw a bar for the background
111119
graphics.set_pen(GREY)
@@ -118,4 +126,3 @@ def clear():
118126

119127
# time to update the display
120128
gu.update(graphics)
121-
# time.sleep(1)

0 commit comments

Comments
 (0)