diff --git a/1 - Code/hl3.py b/1 - Code/hl3.py index a187bff9808a88e24f1fe86e55722402f43eddcf..077170385e60bd7442b47142f06df020825b3f09 100644 --- a/1 - Code/hl3.py +++ b/1 - Code/hl3.py @@ -1,7 +1,8 @@ from machine import Pin from neopixel import NeoPixel +import utime -nb_line = 8 +nb_line = 16 nb_row = 8 gpio_neopixel = 0 @@ -41,6 +42,93 @@ class color: ORANGE_DARK = (204, 102, 0) ORANGE = (255, 128, 0) ORANGE_YELLOW = (255, 204, 0) + +# use https://goo.gl/gGYfJV to add new chars +__TEXT_DICT = { + ' ': [], + 'A': [14, 17, 17, 31, 17, 17, 17], + 'B': [15, 17, 17, 31, 17, 17, 15], + 'C': [14, 17, 1, 1, 1, 17, 14], + 'D': [15, 17, 17, 17, 17, 17, 15], + 'E': [31, 1, 1, 15, 1, 1, 31], + 'F': [31, 1, 1, 15, 1, 1, 1], + 'G': [14, 17, 1, 1, 25, 17, 30], + 'H': [17, 17, 17, 31, 17, 17, 17], + 'I': [31, 4, 4, 4, 4, 4, 31], + 'J': [31, 16, 16, 16, 16, 17, 14], + 'K': [17, 17, 9, 7, 9, 17, 17], + 'L': [1, 1, 1, 1, 1, 1, 31], + 'M': [17, 27, 27, 21, 21, 17, 17], + 'N': [17, 19, 21, 21, 25, 17, 17], + 'O': [14, 17, 17, 17, 17, 17, 14], + 'P': [15, 17, 17, 17, 15, 1, 1], + 'Q': [14, 17, 17, 17, 17, 21, 14, 4, 8], + 'R': [15, 17, 17, 15, 9, 17, 17], + 'S': [30, 1, 1, 14, 16, 16, 15], + 'T': [31, 4, 4, 4, 4, 4, 4], + 'U': [17, 17, 17, 17, 17, 17, 14], + 'V': [17, 17, 17, 17, 10, 10, 4], + 'W': [17, 17, 21, 21, 21, 10, 10], + 'X': [17, 17, 10, 4, 10, 17, 17], + 'Y': [17, 10, 4, 4, 4, 4, 4], + 'Z': [31, 16, 8, 4, 2, 1, 31], + 'a': [0, 0, 14, 16, 30, 17, 30], + 'b': [1, 1, 13, 19, 17, 17, 15], + 'c': [0, 0, 14, 17, 1, 17, 14], + 'd': [16, 16, 30, 17, 17, 17, 14], + 'e': [0, 0, 14, 17, 31, 1, 30], + 'f': [24, 4, 30, 4, 4, 4, 31], + 'g': [0, 0, 30, 17, 17, 25, 22, 16, 14], + 'h': [1, 1, 15, 17, 17, 17, 17], + 'i': [4, 0, 7, 4, 4, 4, 31], + 'j': [16, 0, 28, 16, 16, 16, 16, 17, 14], + 'k': [1, 1, 9, 9, 7, 9, 17], + 'l': [7, 4, 4, 4, 4, 4, 31], + 'm': [0, 0, 21, 31, 21, 21, 21], + 'n': [0, 0, 13, 19, 17, 17, 17], + 'o': [0, 0, 14, 17, 17, 17, 14], + 'p': [0, 0, 13, 19, 17, 17, 15, 1, 1], + 'q': [0, 0, 30, 17, 17, 25, 22, 16, 16], + 'r': [0, 0, 27, 6, 2, 2, 15], + 's': [0, 0, 30, 1, 14, 16, 15], + 't': [0, 4, 31, 4, 4, 4, 24], + 'u': [0, 0, 17, 17, 17, 25, 22], + 'v': [0, 0, 17, 17, 10, 10, 4], + 'w': [0, 0, 17, 21, 21, 10, 10], + 'x': [0, 0, 17, 17, 14, 17, 17], + 'y': [0, 0, 17, 17, 10, 10, 4, 4, 3], + 'z': [0, 0, 31, 8, 4, 2, 31], + '0': [14, 25, 21, 21, 21, 19, 14], + '1': [4, 7, 4, 4, 4, 4, 31], + '2': [14, 17, 16, 14, 1, 1, 31], + '3': [14, 17, 16, 14, 16, 17, 14], + '4': [8, 12, 10, 9, 31, 8, 8], + '5': [31, 1, 1, 15, 16, 16, 15], + '6': [12, 2, 1, 15, 17, 17, 14], + '7': [31, 16, 8, 4, 2, 2, 2], + '8': [14, 17, 17, 14, 17, 17, 14], + '9': [14, 17, 17, 30, 16, 8, 6], + '.': [0, 0, 0, 0, 0, 4, 4], + ',': [0, 0, 0, 0, 0, 4, 4, 2], + ';': [0, 0, 4, 4, 0, 4, 4, 2], + '?': [14, 17, 16, 12, 0, 4, 4], + '!': [4, 4, 4, 4, 0, 4, 4], + '-': [0, 0, 0, 0, 14], + '_': [0, 0, 0, 0, 0, 0, 31], + '*': [0, 0, 10, 4, 10], + '+': [0, 0, 4, 4, 31, 4, 4], + '/': [16, 16, 8, 4, 4, 2, 2], + '\\': [2, 2, 4, 8, 8, 16, 16], + '<': [0, 0, 8, 4, 2, 4, 8], + '>': [0, 0, 2, 4, 8, 4, 2], + '#': [10, 10, 31, 10, 31, 10, 10], + '=': [0, 0, 0, 31, 0, 31], + '\'': [8, 8, 4], + '%': [11, 11, 4, 2, 2, 13, 13, 0, 0], + '&': [6, 1, 1, 6, 5, 9, 22, 0, 0], + '@': [14, 17, 29, 27, 31, 1, 30, 0, 0], + '$': [4, 30, 5, 14, 20, 15, 4, 0, 0], +} def col(r, g, b): return (r, g, b) @@ -140,3 +228,34 @@ class matrix: hex_color = (r << 16) | (g << 8) | b return hex_color + +def afficher_texte(text, color, speed): + + # Clear the screen + matrix.clear(0) + + width = 5 + height = 8 + h_offset = 8 + spacewidth = 2 + + def printColumn(step, xpos, text): + if step < h_offset or step >= h_offset + len(text) * (width + spacewidth): + char = ' ' + col = 0 + else: + step -= h_offset + char = text[step // (width + spacewidth)] + col = step % (width + spacewidth) + if char not in __TEXT_DICT: + char = ' ' + colbit = 1 << col + charMap = __TEXT_DICT[char] + for line in range(height): + colored = len(charMap) > line and charMap[line] & colbit + matrix.set_led(xpos, line, color if colored else 0) + + for step in range(h_offset + len(text) * (width + spacewidth) + 1): + for i in range(nb_row): + printColumn(step + i, i, text) + utime.sleep(speed) \ No newline at end of file diff --git a/1 - Code/main.py b/1 - Code/main.py index b105a4644da006403104de94e506594b8d739318..58feec519b74bb715826fb45b33dd4be1cf5c486 100644 --- a/1 - Code/main.py +++ b/1 - Code/main.py @@ -1,23 +1,4 @@ from hl3 import * import time -matrix.clear(0) - -matrix.set_led(5, 5, color.GREEN) -print(matrix.get_led(5,5)) - -for i in range(8): - matrix.set_line(i, color.RED) - time.sleep(0.1) - matrix.set_line(i, 0) - -for i in range(8): - matrix.set_column(i, color.RED) - time.sleep(0.1) - matrix.set_column(i, 0) - -for i in range(8): - for j in range(8): - matrix.set_led(j, i, color.RED) - time.sleep(0.1) - matrix.set_led(j, i, 0) +afficher_texte("Hello world!", color.ORANGE, 0.1) diff --git a/2 - Reports/Michael_Divia.md b/2 - Reports/Michael_Divia.md index c6f7e946ea3238dd8811eabd4979f06d78d66ae4..2932f92f3569cfc027e960f7efc914c7b0ed3a4c 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 aussi profité d'implémenter toute les couleurs que nous devions implémentées d'après la documentation. J'ai ensuite enchaîné avec l'ajout de la fonction `set_line`,`set_column`, `set_led`, `get_led`. +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. J'ai ensuite enchaîné avec l'ajout de la fonction `set_line`,`set_column`, `set_led`, `get_led` puis, avec l'aide de Gaspard, nous avons implémenter la fonction `afficher_texte`. # Creators