1111"""
1212
1313# Variables
14- tiny = TinyFX () # Create a new TinyFX object to interact with the board
15- monoplayer = MonoPlayer (tiny .outputs ) # Create a new effect player to control TinyFX's mono outputs
16- rgbplayer = ColourPlayer (tiny .rgb ) # Create a new effect player to control TinyFX's RGB output
17- mono_effects = EffectPackage (tiny , "Mono" , 6 ) # Create a new EffectPackage to take care of all the different effect settings for each mono channel.
18- rgb_effects = EffectPackage (tiny , "RGB" , 1 ) # Create a new EffectPackage to take care of all the different effect settings for the RGB channel.
14+ tiny = TinyFX () # Create a new TinyFX object to interact with the board
15+ monoplayer = MonoPlayer (tiny .outputs ) # Create a new effect player to control TinyFX's mono outputs
16+ rgbplayer = ColourPlayer (tiny .rgb ) # Create a new effect player to control TinyFX's RGB output
17+ mono_effects = EffectPackage ("Mono" , 6 ) # Create a new EffectPackage to take care of all the different effect settings for each mono channel.
18+ rgb_effects = EffectPackage ("RGB" , 1 ) # Create a new EffectPackage to take care of all the different effect settings for the RGB channel.
1919mono_channel = 1
2020run_mode = 0
2121
@@ -26,17 +26,19 @@ class Mode:
2626 RGB = 2
2727
2828
29- def select_channel (dir , repeat ):
30- # Selecting a channel just involves incrementing or decrementing the selected_channel variable,
31- # looping it round if it goes above the total number of channels or below zero.
32-
29+ def rotate (dir , repeat ):
30+ # If the TinyFX is just running this button doesn't do anything.
3331 if run_mode == Mode .Running :
3432 return
35-
33+
34+ # However, if we're in RGB editing mode then we're altering the hue.
3635 if run_mode == Mode .RGB :
3736 rgb_effects .alter_hue (0 , dir * 5 )
3837 rgb_effects .update_effects_list (rgbplayer )
39-
38+
39+ # And if we're in mono editing mode this selects the channel.
40+ # Selecting a channel just involves incrementing or decrementing the selected_channel variable,
41+ # looping it round if it goes above the total number of channels or below zero.
4042 elif run_mode == Mode .Mono and not repeat :
4143 global mono_channel
4244
@@ -46,7 +48,7 @@ def select_channel(dir, repeat):
4648 if mono_channel < 1 :
4749 mono_channel = len (mono_effects .channel_settings )
4850
49- # Otherwise we just loop through each channel and undim it if it's the selected
51+ # Then we just loop through each channel and undim it if it's the selected
5052 # channel or dim it if it's not.
5153 for i in range (len (mono_effects .channel_settings )):
5254 effect = mono_effects .channel_settings [i ]
@@ -55,7 +57,7 @@ def select_channel(dir, repeat):
5557 else :
5658 effect .dim ()
5759
58- # This is important when any changes are made. It takes the settings data from the
60+ # Calling this is important when any changes are made. It takes the settings data from the
5961 # channel settings and actually applies them to the player class.
6062 mono_effects .update_effects_list (monoplayer )
6163
@@ -64,11 +66,11 @@ def toggle_mono(channel=0):
6466 # This controls the quick mute for each channel. It goes straight into the
6567 # player and sets the brightness to zero, or to whatever's in the
6668 # settings for that channel if it's already at zero.
67-
69+
6870 if channel > 0 :
6971 effect = monoplayer .effects [channel - 1 ]
7072 old_brightness = mono_effects .channel_settings [channel - 1 ].brightness
71-
73+
7274 else :
7375 effect = rgbplayer .effects [0 ]
7476 old_brightness = rgb_effects .channel_settings [channel - 1 ].brightness
@@ -82,22 +84,31 @@ def toggle_mono(channel=0):
8284 brightness = old_brightness
8385 effect .brightness = brightness
8486
87+
8588def saving_handler ():
8689 # Saving is simpler than loading, first we put in a bit of text directing the user to the instructions:
8790 text = "# SETTINGS FILE\n #\n # For instructions, check readme.txt\n #\n "
8891
92+ # Then add in each channel's settings.
8993 text += mono_effects .save_settings ()
9094 text += rgb_effects .save_settings ()
95+
9196 # Finally save the file.
9297 with open ("settings.txt" , "w" ) as settingsfile :
9398 settingsfile .write (text )
94-
99+
100+
95101def mode_handler ():
102+ # Here we're just switching between the running mode, mono editing mode and
103+ # RGB editing mode.
96104 global run_mode
97105
98106 run_mode += 1
99107 if run_mode > 2 :
100108 run_mode = 0
109+
110+ # That's the actual switch done, the rest just dims or brightens LEDs
111+ # appropriately for the current mode.
101112 if run_mode == Mode .Running :
102113 for i in range (len (mono_effects .channel_settings )):
103114 mono_effects .channel_settings [i ].undim ()
@@ -118,6 +129,7 @@ def mode_handler():
118129 mono_effects .update_effects_list (monoplayer )
119130 rgb_effects .update_effects_list (rgbplayer )
120131
132+
121133def common_handler (button ):
122134 # This handles presses on the buttons common to all effect types.
123135 # It gets passed which button was pressed and depending on which it was,
@@ -130,12 +142,12 @@ def common_handler(button):
130142
131143 if run_mode == Mode .Running :
132144 return
133-
145+
134146 if run_mode == Mode .Mono :
135147 player = monoplayer
136148 effects = mono_effects
137149 selected_channel = mono_channel
138-
150+
139151 if run_mode == Mode .RGB :
140152 player = rgbplayer
141153 effects = rgb_effects
@@ -172,7 +184,7 @@ def number_handler(number_button, repeat):
172184 selected_channel = mono_channel
173185 effects = mono_effects
174186 effect = effects .channel_settings [selected_channel - 1 ]
175-
187+
176188 elif run_mode == Mode .RGB :
177189 player = rgbplayer
178190 selected_channel = 0
@@ -225,7 +237,7 @@ def number_handler(number_button, repeat):
225237 elif number_button == 9 :
226238 if effect .type in (3 , 9 ) and not repeat :
227239 effects .alter_flashes (selected_channel , 1 )
228-
240+
229241 elif number_button == 0 :
230242 if effect .type == 10 :
231243 effects .alter_hue2 (0 , 5 )
@@ -243,8 +255,8 @@ def number_handler(number_button, repeat):
243255# This binds functions to each of the Pimoroni remote's buttons for what happens when they're pressed, and when they're held.
244256# For the most part they're set to pass to a handler for the reasons mentioned above.
245257remote = PimoroniRemote ()
246- remote .bind ("CLOCKWISE" , (select_channel , 1 ,False ), on_repeat = (select_channel , 1 ,True ))
247- remote .bind ("ANTICLOCK" , (select_channel , - 1 , False ), on_repeat = (select_channel , - 1 ,True ))
258+ remote .bind ("CLOCKWISE" , (rotate , 1 , False ), on_repeat = (rotate , 1 , True ))
259+ remote .bind ("ANTICLOCK" , (rotate , - 1 , False ), on_repeat = (rotate , - 1 , True ))
248260remote .bind ("MENU/ACTION" , (mode_handler ), on_repeat = None )
249261remote .bind ("1/RED" , (number_handler , 1 , False ), on_repeat = (number_handler , 1 , True ))
250262remote .bind ("2/GREEN" , (number_handler , 2 , False ), on_repeat = (number_handler , 2 , True ))
0 commit comments