Created
May 22, 2023 02:40
-
-
Save jposada202020/abbbb6271c1118bcec5ac2bb68e53c6d to your computer and use it in GitHub Desktop.
Example widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| import displayio | |
| import board | |
| import terminalio | |
| from gauge import gauge | |
| from ulab import numpy as np | |
| from circuitpython_uplot.uplot import Uplot | |
| from circuitpython_uplot.ucartesian import ucartesian | |
| from circuitpython_simple_dial.simple_dial import Dial | |
| from circuitpython_simple_dial.dial_needle import needle | |
| from scales import Scale | |
| from arrowline import Line | |
| from adafruit_display_text import bitmap_label | |
| from adafruit_bitmap_font import bitmap_font | |
| display = board.DISPLAY | |
| MEDIUM_FONT = bitmap_font.load_font("/fonts/LeagueSpartan-Bold-16.bdf") | |
| group = displayio.Group() | |
| palette = displayio.Palette(3) | |
| x0=5 | |
| y0=5 | |
| points=[(x0, y0), (100, 20), (20, 20), (20, 100)] | |
| palette[0] = 0xFF0000 | |
| palette[1] = 0x00FF00 | |
| palette[2] = 0x0000FF | |
| left_text = bitmap_label.Label( | |
| MEDIUM_FONT, | |
| text="Simple Dial", | |
| color=0x000000, | |
| background_color=0x999999, | |
| x=340, | |
| y=160, | |
| ) | |
| upper_text = bitmap_label.Label( | |
| MEDIUM_FONT, | |
| text="Gauge", | |
| color=0x000000, | |
| background_color=0x999999, | |
| x=120, | |
| y=120, | |
| ) | |
| bottom_text = bitmap_label.Label( | |
| MEDIUM_FONT, | |
| text="Scales", | |
| color=0x000000, | |
| background_color=0x999999, | |
| x=160, | |
| y=200, | |
| ) | |
| bitmap = displayio.Bitmap(480, 320, 5) | |
| screen_palette = displayio.Palette(3) | |
| screen_palette[0] = 0xD1ADA0 | |
| screen_palette[1] = 0x00AA00 | |
| screen_tilegrid = displayio.TileGrid( | |
| bitmap, | |
| pixel_shader=screen_palette, | |
| x=0, | |
| y=0, | |
| ) | |
| group.append(screen_tilegrid) | |
| group.append(left_text) | |
| group.append(upper_text) | |
| group.append(bottom_text) | |
| a = Line( | |
| screen_tilegrid, | |
| 320, | |
| 0, | |
| 320, | |
| 340, | |
| 12, | |
| screen_palette, | |
| 1, | |
| solid_line=False, | |
| line_width=4, | |
| line_length=5, | |
| line_space=5, | |
| ) | |
| group.append(a.draw) | |
| b = Line( | |
| screen_tilegrid, | |
| 320, | |
| 160, | |
| -20, | |
| 160, | |
| 12, | |
| screen_palette, | |
| 1, | |
| solid_line=False, | |
| line_width=4, | |
| line_length=5, | |
| line_space=5, | |
| ) | |
| group.append(b.draw) | |
| my_dial = Dial( | |
| x=350, # set x-position | |
| y=15, # set y-position | |
| width=100, # requested width of the dial | |
| height=100, # requested height of the dial | |
| padding=12, # add 12 pixels around the dial to make room for labels | |
| tick_label_font=terminalio.FONT, # the font used for the tick labels | |
| ) | |
| my_dial2 = Dial( | |
| x=340, # set x-position | |
| y=200, # set y-position | |
| width=120, # requested width of the dial | |
| height=120, # requested height of the dial | |
| padding=12, # add 12 pixels around the dial to make room for labels | |
| tick_label_font=terminalio.FONT, # the font used for the tick labels | |
| ) | |
| my_needle2 = needle(my_dial2,needle_width=5, needle_pad=20,needle_full=True, needle_color=0xFFFF8F) | |
| my_needle = needle(my_dial) | |
| group.append(my_dial) | |
| group.append(my_dial2) | |
| gauge1 = gauge( | |
| 40, | |
| 15, | |
| 28, | |
| 100, | |
| ticks=[50], | |
| scale_range=[0, 100], | |
| tick_color=0x0000FF, | |
| background_color=(0,3,39), | |
| ) | |
| gauge1.set_threshold(value=50, color=0xFF0000) | |
| gauge2 = gauge( | |
| 240, | |
| 15, | |
| 26, | |
| 100, | |
| ticks=[10,20,30,40,50, 60, 70, 80, 90], | |
| scale_range=[0, 100], | |
| tick_color=0xFF0000, | |
| background_color=(0,3,39), | |
| show_text=True, | |
| ) | |
| group.append(gauge1) | |
| group.append(gauge2) | |
| gauge3 = gauge( | |
| 100, | |
| 15, | |
| 28, | |
| 100, | |
| ticks=[10,50, 90], | |
| scale_range=[0, 100], | |
| tick_color=0x0000FF, | |
| background_color=0x00FF00, | |
| show_text=True, | |
| direction="Horizontal" | |
| ) | |
| gauge3.set_threshold(value=50, color=0xFF0000) | |
| group.append(gauge3) | |
| my_scale = Scale( | |
| x=60, | |
| y=285, | |
| length=90, | |
| width=30, | |
| direction="vertical", | |
| limits=(0, 80), | |
| ) | |
| my_scale3 = Scale( | |
| x=140, | |
| y=280, | |
| length=100, | |
| width=40, | |
| back_color=0x123456, | |
| direction="horizontal", | |
| limits=(0, 80), | |
| ticks=[16, 32, 48, 64, 80], | |
| ) | |
| group.append(my_scale3) | |
| group.append(my_scale) | |
| display.show(group) | |
| # some dummy date to show library capabilities | |
| i = 20 | |
| # we iterate | |
| while True: | |
| for a in range(5): | |
| gauge1.update(i) | |
| gauge2.update(i) | |
| gauge3.update(i) | |
| if i % 2 == 0: | |
| my_needle2.value = i | |
| my_needle.value = i | |
| my_scale.animate_pointer(i) | |
| my_scale3.animate_pointer(i) | |
| i = i + 10 | |
| time.sleep(0.05) | |
| for a in range(5): | |
| gauge1.update(i) | |
| gauge2.update(i-20) | |
| gauge3.update(i) | |
| my_needle.value = i | |
| my_scale.animate_pointer(i) | |
| my_scale3.animate_pointer(i) | |
| i = i - 10 | |
| time.sleep(0.05) | |
| i = 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment