From 8858872c798f342133a51ac4c3a528d702987f46 Mon Sep 17 00:00:00 2001
From: "michael.divia" <michael.divia@etu.hesge.ch>
Date: Tue, 18 Jun 2024 10:42:13 +0200
Subject: [PATCH] set_led function

---
 1 - Code/hl3.py  | 17 +++++++++++++++++
 1 - Code/main.py |  6 ++++++
 2 files changed, 23 insertions(+)

diff --git a/1 - Code/hl3.py b/1 - Code/hl3.py
index 75c2805..e73af30 100644
--- a/1 - Code/hl3.py	
+++ b/1 - Code/hl3.py	
@@ -107,3 +107,20 @@ class matrix:
         
         # Apply the array
         np.write()
+    
+    def set_led(column, line, color):
+        
+        # Check bounds
+        if line < 0 or line >= nb_line:
+            raise ValueError("Line is out of bound")
+        if column < 0 or column >= nb_row:
+            raise ValueError("Column is out of bound")
+        
+        # Convert the color
+        color = color_convert(color)
+        
+        # Set the specific LED to the color
+        np[line * nb_row + column] = color
+        
+        # Apply the array
+        np.write()
diff --git a/1 - Code/main.py b/1 - Code/main.py
index 095766a..0f428f2 100644
--- a/1 - Code/main.py	
+++ b/1 - Code/main.py	
@@ -12,3 +12,9 @@ for i in range(8):
     matrix.set_column(i, color.RED)
     time.sleep(0.2)
     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)
\ No newline at end of file
-- 
GitLab