|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import time |
| 6 | +import board |
| 7 | +import displayio |
| 8 | +import random |
| 9 | +from circuitpython_uplot.plot import Plot, color |
| 10 | +from circuitpython_uplot.logging import Logging |
| 11 | +from dial_gauge import DIAL_GAUGE |
| 12 | + |
| 13 | +# In order to run this example you need to install the following library: |
| 14 | +# - CircuitPython_DIAL_GAUGE (from https://github.com/jposada202020/CircuitPython_DIAL_GAUGE) |
| 15 | + |
| 16 | +rangey_values = [0, 110] |
| 17 | + |
| 18 | +display = board.DISPLAY |
| 19 | +display.auto_refresh = False |
| 20 | +my_plot = Plot(0, 0, display.width // 2, display.height // 2) |
| 21 | +plot2 = Plot(display.width // 2, 0, display.width // 2, display.height // 2) |
| 22 | + |
| 23 | +my_dial = DIAL_GAUGE(60, 50, 60, 40, range_values=rangey_values, color=color.BLUE) |
| 24 | + |
| 25 | +plot2.append(my_dial) |
| 26 | + |
| 27 | +g = displayio.Group() |
| 28 | +g.append(my_plot) |
| 29 | +g.append(plot2) |
| 30 | +display.show(g) |
| 31 | + |
| 32 | + |
| 33 | +my_plot.tick_params( |
| 34 | + tickx_height=4, |
| 35 | + ticky_height=4, |
| 36 | + show_ticks=True, |
| 37 | + tickcolor=color.TEAL, |
| 38 | + showtext=True, |
| 39 | +) |
| 40 | + |
| 41 | +# Creating the x and y data |
| 42 | +x = [ |
| 43 | + 10, |
| 44 | + 20, |
| 45 | + 30, |
| 46 | + 40, |
| 47 | + 50, |
| 48 | + 60, |
| 49 | + 70, |
| 50 | + 80, |
| 51 | + 90, |
| 52 | + 100, |
| 53 | + 110, |
| 54 | + 120, |
| 55 | + 130, |
| 56 | + 140, |
| 57 | + 150, |
| 58 | + 160, |
| 59 | + 170, |
| 60 | + 180, |
| 61 | + 190, |
| 62 | +] |
| 63 | +y = [] |
| 64 | + |
| 65 | +# Creating the random numbers |
| 66 | +random_numbers = [32, 34, 45, 65, 24, 40, 18, 27] |
| 67 | + |
| 68 | + |
| 69 | +# display.show(my_plot) |
| 70 | +display.refresh() |
| 71 | + |
| 72 | +dist = 0 |
| 73 | + |
| 74 | +# Creating the loggraph |
| 75 | +my_loggraph = Logging( |
| 76 | + my_plot, |
| 77 | + x[0:dist], |
| 78 | + y[0:dist], |
| 79 | + rangex=[0, 210], |
| 80 | + rangey=rangey_values, |
| 81 | + line_color=color.BLUE, |
| 82 | + ticksx=[25, 50, 75, 100, 125, 150, 175, 200], |
| 83 | + ticksy=[25, 50, 75, 100], |
| 84 | + limits=[30, 60], |
| 85 | +) |
| 86 | + |
| 87 | +# Showing the loggraph |
| 88 | +for i in range(150): |
| 89 | + if dist > len(x): |
| 90 | + y.pop(0) |
| 91 | + |
| 92 | + update_value = random.choice(random_numbers) |
| 93 | + y.append(update_value) |
| 94 | + |
| 95 | + my_loggraph.draw_points(my_plot, x[0:dist], y[0:dist]) |
| 96 | + |
| 97 | + if dist > len(x): |
| 98 | + my_dial.update(update_value) |
| 99 | + else: |
| 100 | + my_dial.update(y[i]) |
| 101 | + display.refresh() |
| 102 | + dist += 1 |
| 103 | + time.sleep(0.5) |
0 commit comments