From 171c3f17cd404ca60e278bba4a506289f68d4e66 Mon Sep 17 00:00:00 2001 From: ploedige Date: Mon, 16 Jan 2023 03:09:25 +0000 Subject: [PATCH] indication_driver V1 finished --- config.py | 15 +++++++++++++++ indication_driver.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 config.py create mode 100644 indication_driver.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..d13097a --- /dev/null +++ b/config.py @@ -0,0 +1,15 @@ +from enum import Enum +import board + +PIXEL_PIN = board.D18 +NUM_PIXELS = 60 +NEOPIXEL_BRIGHTNESS = 0.2 + + +TRASH_LOCATION = { + "COMBUSTIBLE" : 5, + "INCOMBUSTIBLE" : 15, + "BOTTLES" : 25, + "CANS" : 35, + "PAPER" : 45 +} \ No newline at end of file diff --git a/indication_driver.py b/indication_driver.py new file mode 100644 index 0000000..e2ced8a --- /dev/null +++ b/indication_driver.py @@ -0,0 +1,28 @@ +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 \ No newline at end of file