From e63a0e7da73802d59cbeb9b2c23a29fed6b10ae2 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 13 Jun 2022 20:17:59 +0100 Subject: [PATCH] AS7262: Update MicroPython example. --- .../breakout_as7262/pico_explorer_graph.py | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/micropython/examples/breakout_as7262/pico_explorer_graph.py b/micropython/examples/breakout_as7262/pico_explorer_graph.py index 43246936..3b46a144 100644 --- a/micropython/examples/breakout_as7262/pico_explorer_graph.py +++ b/micropython/examples/breakout_as7262/pico_explorer_graph.py @@ -1,17 +1,16 @@ from pimoroni_i2c import PimoroniI2C from breakout_as7262 import BreakoutAS7262 -import picoexplorer as display +import picographics import time -width = display.get_width() -height = display.get_height() + +display = picographics.PicoGraphics(picographics.DISPLAY_PICO_EXPLORER) + +width, height = display.get_bounds() bar_width = width // 6 bar_height = height -display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565) -display.init(display_buffer) - i2c = PimoroniI2C(20, 21) as7 = BreakoutAS7262(i2c) @@ -31,35 +30,44 @@ def draw_bar(v, i): display.rectangle(i * bar_width, current_bar_top, bar_width, current_bar_height - 1) +BLACK = display.create_pen(0, 0, 0) +RED = display.create_pen(255, 0, 0) +ORANGE = display.create_pen(255, 128, 0) +YELLOW = display.create_pen(255, 255, 0) +GREEN = display.create_pen(0, 255, 0) +BLUE = display.create_pen(0, 0, 255) +VIOLET = display.create_pen(255, 0, 255) + + while True: r, o, y, g, b, v = as7.read() m = max(r, o, y, g, b, v) - display.set_pen(0, 0, 0) + display.set_pen(BLACK) display.clear() # Red - display.set_pen(255, 0, 0) + display.set_pen(RED) draw_bar(r / m, 0) # Orange - display.set_pen(255, 128, 0) + display.set_pen(ORANGE) draw_bar(o / m, 1) # Yellow - display.set_pen(255, 255, 0) + display.set_pen(YELLOW) draw_bar(y / m, 2) # Green - display.set_pen(0, 255, 0) + display.set_pen(GREEN) draw_bar(g / m, 3) # Blue - display.set_pen(0, 0, 255) + display.set_pen(BLUE) draw_bar(b / m, 4) # Violet - display.set_pen(255, 0, 255) + display.set_pen(VIOLET) draw_bar(v / m, 5) display.update()