From d14be82cd0ec364b01b3336e48c2eaf9f07a0e6a Mon Sep 17 00:00:00 2001 From: "michael.divia" <michael.divia@etu.hesge.ch> Date: Tue, 18 Jun 2024 10:14:00 +0200 Subject: [PATCH] function set_line working --- 1 - Code/hl3.py | 32 ++++++++++++++++++++++++-------- 1 - Code/main.py | 2 +- 2 - Reports/Michael_Divia.md | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/1 - Code/hl3.py b/1 - Code/hl3.py index cdbe869..d89e597 100644 --- a/1 - Code/hl3.py +++ b/1 - Code/hl3.py @@ -1,10 +1,13 @@ from machine import Pin from neopixel import NeoPixel -np_led = 64 +nb_line = 8 +nb_row = 8 gpio_neopixel = 0 -class Color: +np = NeoPixel(Pin(gpio_neopixel, Pin.OUT), nb_line*nb_row) + +class color: BLACK = (0, 0, 0) BLUE = (0, 0, 255) CYAN = (0, 255, 255) @@ -38,14 +41,27 @@ class Color: ORANGE_DARK = (204, 102, 0) ORANGE = (255, 128, 0) ORANGE_YELLOW = (255, 204, 0) - - -def init_neopixel(): - return NeoPixel(Pin(gpio_neopixel, Pin.OUT), np_led) + +def col(r, g, b): + return (r, g, b) class matrix: def clear(color): - np = init_neopixel() - for i in range(np_led): + + # Handle hex an 0 + if isinstance(color, int): + if color == 0: + color = (0, 0, 0) + else: + color = ((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF) + # Handle RGB tuple + elif isinstance(color, tuple) and len(color) == 3: + pass + # Error + else: + raise ValueError("Color must be an RGB tuple, a hex value, 0 or a valide color from the color class") + + for i in range(nb_line*nb_row): np[i] = color + np.write() \ No newline at end of file diff --git a/1 - Code/main.py b/1 - Code/main.py index c9e354a..57c5091 100644 --- a/1 - Code/main.py +++ b/1 - Code/main.py @@ -1,4 +1,4 @@ from hl3 import color from hl3 import matrix -matrix.clear(color.RED) \ No newline at end of file +matrix.clear(color.RED) diff --git a/2 - Reports/Michael_Divia.md b/2 - Reports/Michael_Divia.md index 6b83542..b27e987 100644 --- a/2 - Reports/Michael_Divia.md +++ b/2 - Reports/Michael_Divia.md @@ -42,7 +42,7 @@ J'ai ensuite pris du temps afin de souder des pin à la matrice de LED afin de f ## Mardi, 18 Juin 2024 -J'ai commencé par créer `hl3.py` afin d'avoir un fichier librairie avec toutes les fonctions que nous allons implémentées. Je me suis ensuite attelé à la finalisation de la fonction `matrix`. +J'ai commencé par créer `hl3.py` afin d'avoir un fichier librairie avec toutes les fonctions que nous allons implémentées. Je me suis ensuite attelé à la finalisation de la fonction `matrix`. J'ai aussi profité d'implémenter toute les couleurs que nous devions implémentées d'après la documentation. # Creators -- GitLab