Simple test
Simple demonstration of the gauge library
import time
import board
from gauge import gauge
# define the display
display = board.DISPLAY
# we create the gauge object
gauge = gauge(
50,
50,
26,
100,
ticks=[10, 50, 90],
scale_range=[0, 100],
tick_color=0x440044,
background_color=0x44FF44,
)
# display the gauge in the screen
display.show(gauge)
# some dummy date to show library capabilities
i = 20
# we iterate
while True:
for a in range(5):
gauge.update(i)
i = i + 10
time.sleep(0.0005)
for a in range(5):
gauge.update(i)
i = i - 10
time.sleep(0.005)
i = 20
AS7341 test
Example showing a AS7341 light sensor with up to 8 gages updating the different colors
import time
import displayio
import board
from adafruit_as7341 import AS7341
from gauge import gauge
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = AS7341(i2c)
display = board.DISPLAY
group = displayio.Group()
gauge1 = gauge(
40,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0x9B26B6,
background_color=0x9B26B6,
)
gauge2 = gauge(
90,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0x4B0082,
background_color=0x4B0082,
)
gauge3 = gauge(
140,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0x0000FF,
background_color=0x0000FF,
)
gauge4 = gauge(
190,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0x00FFFF,
background_color=0x00FFFF,
)
gauge5 = gauge(
240,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0x00FF00,
background_color=0x00FF00,
)
gauge6 = gauge(
290,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0xFFFF00,
background_color=0xFFFF00,
)
gauge7 = gauge(
340,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0xFF6500,
background_color=0xFF6500,
)
gauge8 = gauge(
390,
50,
26,
100,
ticks=[0, 3000],
scale_range=[0, 3000],
tick_color=0x440044,
box_color=0xFF0000,
background_color=0xFF0000,
)
group.append(gauge1)
group.append(gauge2)
group.append(gauge3)
group.append(gauge4)
group.append(gauge5)
group.append(gauge6)
group.append(gauge7)
group.append(gauge8)
display.show(group)
while True:
gauge1.update(sensor.channel_415nm)
gauge2.update(sensor.channel_445nm)
gauge3.update(sensor.channel_480nm)
gauge4.update(sensor.channel_515nm)
gauge5.update(sensor.channel_555nm)
gauge6.update(sensor.channel_590nm)
gauge7.update(sensor.channel_630nm)
gauge8.update(sensor.channel_680nm)
time.sleep(0.001)
Threshold Setting Example test
Example showing how to set the threshold limit to change the bar color
import time
import board
from gauge import gauge
# define the display
display = board.DISPLAY
# we create the gauge object
gauge = gauge(
50,
50,
26,
100,
ticks=[50],
scale_range=[0, 100],
tick_color=0x0000FF,
background_color=0x44FF44,
)
gauge.set_threshold(value=50, color=0xFF0000)
# display the gauge in the screen
display.show(gauge)
# some dummy date to show library capabilities
i = 20
# we iterate
while True:
for a in range(5):
gauge.update(i)
i = i + 10
time.sleep(0.05)
for a in range(5):
gauge.update(i)
i = i - 10
time.sleep(0.05)
i = 20
Horizontal Gauge
Example showing how to set horizontal gages
import time
import displayio
import board
from gauge import gauge
display = board.DISPLAY
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
gauge1 = gauge(
20,
15,
28,
100,
ticks=[10, 50, 90],
scale_range=[0, 100],
tick_color=0x0000FF,
background_color=(0, 3, 39),
show_text=True,
)
gauge1.set_threshold(value=50, color=0xFF0000)
group.append(gauge1)
gauge2 = gauge(
60,
80,
28,
100,
ticks=[10, 50, 90],
scale_range=[0, 100],
tick_color=0x0000FF,
background_color=0x00FF00,
show_text=True,
direction="Horizontal",
)
gauge2.set_threshold(value=50, color=0xFF0000)
group.append(gauge2)
display.show(group)
i = 20
gauge1.update(i)
gauge2.update(i)
# we iterate
while True:
for a in range(5):
gauge1.update(i)
gauge2.update(i)
i = i + 10
time.sleep(0.1)
for a in range(5):
gauge1.update(i)
gauge2.update(i)
i = i - 10
time.sleep(0.1)
i = 20