AS7262: Update MicroPython example.

driver/sh1107
Phil Howard 2022-06-13 20:17:59 +01:00
rodzic 5d7113e8c9
commit e63a0e7da7
1 zmienionych plików z 21 dodań i 13 usunięć

Wyświetl plik

@ -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()