1
1
"""
2
2
LED Logik
3
3
"""
4
+ import time
4
5
import tkinter as tk
5
6
from tkinter import ttk
6
7
from util import rgb_perc
@@ -9,7 +10,7 @@ class LED(tk.Canvas):
9
10
"""
10
11
Repräsentiert eine LED
11
12
"""
12
- def __init__ (self , master , color = "red " , ** kwargs ):
13
+ def __init__ (self , master , color = "black " , ** kwargs ):
13
14
super ().__init__ (master , height = 20 , width = 20 , ** kwargs , bg = color )
14
15
15
16
def set_color (self , color ):
@@ -59,6 +60,7 @@ def __init__(self, master, amount_columns, leds_per_column):
59
60
master .rowconfigure (0 , weight = 1 )
60
61
61
62
self .strips = []
63
+ self .amount_leds = amount_columns * leds_per_column
62
64
63
65
for i in range (amount_columns ):
64
66
strip = LEDStrip (master , amount_leds = leds_per_column )
@@ -73,6 +75,12 @@ def set_all(self, color):
73
75
for strip in self .strips :
74
76
strip .set_all (color )
75
77
78
+ def set_led (self , index , color ):
79
+ """ setzt eine LED auf eine bestimmte Farbe """
80
+ strip_index = index // self .leds_per_column
81
+ led_index = index % self .leds_per_column
82
+ self .strips [strip_index ].set_color (led_index , color )
83
+
76
84
def run_effect (self , effect : str ):
77
85
"""
78
86
Führt einen Effekt aus
@@ -81,6 +89,26 @@ def run_effect(self, effect: str):
81
89
case "rainbow" :
82
90
for i in range (self .amount_columns ):
83
91
for j in range (self .leds_per_column ):
84
- self .strips [i ].set_color (j , rgb_perc (10 , 40 , 50 )) # perc / 100 * 255
92
+ self .strips [i ].set_color (j , rgb_perc (10 , 40 , 50 ))
93
+ case "main" :
94
+ blue = True
95
+ while True :
96
+ for i in range (100 ):
97
+ for j in range (self .amount_columns ):
98
+ if not blue :
99
+ self .strips [j ].set_color (i , rgb_perc (0 , 0 , 100 ))
100
+ self .set_led (i , rgb_perc (0 , 0 , 100 ))
101
+ blue = True
102
+ else :
103
+ self .strips [j ].set_color (i , rgb_perc (0 , 0 , 0 ))
104
+ blue = False
105
+ time .sleep (0.1 )
106
+ self .update ()
107
+ case "testing" :
108
+ for i in range (self .amount_leds ):
109
+ self .set_led (i , rgb_perc (0 , 0 , 100 ))
110
+ time .sleep (0.1 )
111
+ self .update ()
112
+
85
113
case _:
86
114
pass
0 commit comments