TREx/indication_driver.py

28 lines
816 B
Python

import neopixel
from config import PIXEL_PIN, NUM_PIXELS, NEOPIXEL_BRIGHTNESS, TRASH_LOCATION
from time import sleep
class IndicationDriver:
def __init__(self):
self.pixels = neopixel.NeoPixel(
PIXEL_PIN,
NUM_PIXELS,
brightness= NEOPIXEL_BRIGHTNESS,
auto_write=False,
pixel_order=neopixel.GRB
)
self.stop()
def stop(self):
self.pixels.fill((0,0,0))
self.pixels.show()
def indicate(self, trash_type: str):
self.stop()
if trash_type in TRASH_LOCATION.keys():
location = TRASH_LOCATION[trash_type]
for idx in range(location-2, location+3):
self.pixels[idx] = (0, 255, 0)
self.pixels.show()
else:
raise ValueError