diff --git a/1 - Code/hl3.py b/1 - Code/hl3.py index cdbe8690c88f334d9c0a78facd73377ae675ce3c..d89e5976d977738e4b4f5df73681614eb927ea30 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 c9e354a6ac58319e6bc6be91169fbb718b1a719b..57c50912f23a853d8c499c8e142bf2ad5597791e 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 6b835423744e79951f4c78649360f36771934f4e..b27e9872c483efb1d8fa9b124365814e34e6d985 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