From 08cb52fbea7013f122c4ec2b9d29eae590f5d7b0 Mon Sep 17 00:00:00 2001 From: Craig Richardson Date: Mon, 14 May 2018 19:44:28 +0100 Subject: [PATCH] Fix formatting issues --- LED_Candles/LED_Candles.py | 26 ++++++++--------- LED_Masquerade_Masks/Audio_Reactive.py | 2 +- LED_Masquerade_Masks/NeoPixel_Gemma_Mask.py | 15 +++++----- LED_Trampoline/LED_Trampoline.py | 3 +- .../Logans_Run_Hand_Jewel_LED.py | 8 +++--- NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py | 4 +-- .../NeoPixel_Jewel_10_Minute_Necklace.py | 28 +++++++++---------- NeoPixel_Punk_Collar/NeoPixel_Punk_Collar.py | 11 ++++---- NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py | 5 ---- NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py | 5 ---- NeoPixel_Tiara/NeoPixel_Tiara.py | 2 +- NeoPixie_Dust_Bag/NeoPixie_Dust_Bag.py | 16 +++++------ .../Sound_Reactive_NeoPixel_Peace_Pendant.py | 5 ++-- raver_bandolier/raver_bandolier.py | 6 ++-- 14 files changed, 63 insertions(+), 73 deletions(-) diff --git a/LED_Candles/LED_Candles.py b/LED_Candles/LED_Candles.py index 601d7fae..dbd76bf9 100644 --- a/LED_Candles/LED_Candles.py +++ b/LED_Candles/LED_Candles.py @@ -70,9 +70,9 @@ state = bright def set_color(index): index = max(min(index, index_max), index_bottom) - if (index >= index_min): + if index >= index_min: strip[0] = [index, int((index * 3) / 8), 0] - elif (index < index_min): + elif index < index_min: strip[0] = [index, int((index * 3.25) / 8), 0] @@ -83,13 +83,13 @@ while True: current_time = time.monotonic() # BRIGHT - if (state == bright): + if state == bright: flicker_msecs = random.randint( 0, down_max_msecs - down_min_msecs) + down_min_msecs flicker_start = current_time index_start = index_end - if ((index_start > index_bottom) and (random.randint(0, 100) < index_bottom_percent)): + if (index_start > index_bottom) and (random.randint(0, 100) < index_bottom_percent): index_end = random.randint( 0, index_start - index_bottom) + index_bottom else: @@ -98,7 +98,7 @@ while True: state = down # DIM - elif (state == dim): + elif state == dim: flicker_msecs = random.randint( 0, up_max_msecs - up_min_msecs) + up_min_msecs flicker_start = current_time @@ -107,25 +107,25 @@ while True: state = down # DIM_HOLD - elif (state == dim_hold): + elif state == dim_hold: # dividing flicker_msecs by 1000 to convert to milliseconds - if (current_time >= (flicker_start + (flicker_msecs / 1000))): - if (state == bright_hold): + if current_time >= (flicker_start + (flicker_msecs / 1000)): + if state == bright_hold: state = bright else: state = dim # DOWN - elif (state == down): + elif state == down: # dividing flicker_msecs by 1000 to convert to milliseconds - if (current_time < (flicker_start + (flicker_msecs / 1000))): + if current_time < (flicker_start + (flicker_msecs / 1000)): set_color(index_start + int(((index_end - index_start) * (((current_time - flicker_start) * 1.0) / flicker_msecs)))) else: set_color(index_end) - if (state == down): - if (random.randint(0, 100) < dim_hold_percent): + if state == down: + if random.randint(0, 100) < dim_hold_percent: flicker_start = current_time flicker_msecs = random.randint( 0, dim_hold_max_msecs - dim_hold_min_msecs) + dim_hold_min_msecs @@ -133,7 +133,7 @@ while True: else: state = dim else: - if (random.randint(0, 100) < bright_hold_percent): + if random.randint(0, 100) < bright_hold_percent: flicker_start = current_time flicker_msecs = random.randint( 0, bright_hold_max_msecs - bright_hold_min_msecs) + bright_hold_min_msecs diff --git a/LED_Masquerade_Masks/Audio_Reactive.py b/LED_Masquerade_Masks/Audio_Reactive.py index b0127d6d..ec72415e 100644 --- a/LED_Masquerade_Masks/Audio_Reactive.py +++ b/LED_Masquerade_Masks/Audio_Reactive.py @@ -16,7 +16,7 @@ while True: signalMin = 65535 signalMax = 0 startTime = time.monotonic() - while ((time.monotonic() - startTime) < sampleWindow): + while (time.monotonic() - startTime) < sampleWindow: signal = mic.value if signal < signalMin: signalMin = signal diff --git a/LED_Masquerade_Masks/NeoPixel_Gemma_Mask.py b/LED_Masquerade_Masks/NeoPixel_Gemma_Mask.py index 08dbab1c..186ad998 100644 --- a/LED_Masquerade_Masks/NeoPixel_Gemma_Mask.py +++ b/LED_Masquerade_Masks/NeoPixel_Gemma_Mask.py @@ -1,10 +1,11 @@ -import board -import neopixel import time -numpix = 5 # Number of NeoPixels +import board +import neopixel + +numpix = 5 # Number of NeoPixels pixpin = board.D1 # Pin where NeoPixels are connected -hue = 0 # Starting color +hue = 0 # Starting color strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.4) @@ -13,9 +14,9 @@ def wheel(pos): # The colours are a transition r - g - b - back to r. if (pos < 0) or (pos > 255): return [0, 0, 0] - elif (pos < 85): + elif pos < 85: return [int(pos * 3), int(255 - (pos * 3)), 0] - elif (pos < 170): + elif pos < 170: pos -= 85 return [int(255 - pos * 3), 0, int(pos * 3)] else: @@ -27,5 +28,5 @@ while True: # Loop forever... for i in range(numpix): strip[i] = wheel((hue + i * 8) & 255) strip.write() - time.sleep(0.02) # 20 ms = ~50 fps + time.sleep(0.02) # 20 ms = ~50 fps hue = (hue + 1) & 255 # Increment hue and 'wrap around' at 255 diff --git a/LED_Trampoline/LED_Trampoline.py b/LED_Trampoline/LED_Trampoline.py index 6e757995..42406147 100644 --- a/LED_Trampoline/LED_Trampoline.py +++ b/LED_Trampoline/LED_Trampoline.py @@ -122,8 +122,7 @@ while True: if mode == 1 and not vibration_switch.value: print("Sparkle mode activate!") pixels.brightness = 1 - sparkle_color_index = ( - sparkle_color_index + 1) % len(sparkle_color_list) + sparkle_color_index = (sparkle_color_index + 1) % len(sparkle_color_list) sparkle_code(sparkle_color_list[sparkle_color_index]) if mode == 2 and not vibration_switch.value: print("Chase mode activate!") diff --git a/Logans_Run_Hand_Jewel_LED/Logans_Run_Hand_Jewel_LED.py b/Logans_Run_Hand_Jewel_LED/Logans_Run_Hand_Jewel_LED.py index bc673c4f..557facb1 100644 --- a/Logans_Run_Hand_Jewel_LED/Logans_Run_Hand_Jewel_LED.py +++ b/Logans_Run_Hand_Jewel_LED/Logans_Run_Hand_Jewel_LED.py @@ -19,14 +19,14 @@ strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False) def lerp(x, x0, x1, y0, y1): # Clamp x within x0 and x1 bounds. - if (x > x1): + if x > x1: x = x1 - if (x < x0): + if x < x0: x = x0 # Calculate linear interpolation of y value. - return (y0 + (y1 - y0) * ((x - x0) / (x1 - x0))) + return y0 + (y1 - y0) * ((x - x0) / (x1 - x0)) # Set all pixels to the specified color. @@ -67,7 +67,7 @@ def animate_gradient_fill(start_r, start_g, start_b, end_r, end_g, end_b, durati # Main animation loop. delta = time.monotonic() - start - while (delta < duration_ms): + while delta < duration_ms: # Calculate how far along we are in the duration as a position 0...1.0 pos = delta / duration_ms # Get the gradient color and fill all the pixels with it. diff --git a/NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py b/NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py index d4b6dadc..c77af09f 100644 --- a/NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py +++ b/NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py @@ -7,7 +7,7 @@ import neopixel try: import urandom as random # for v1.0 API support -except: +except ImportError: import random num_leds = 24 # 24 LED NeoPixel ring @@ -60,7 +60,7 @@ while True: # Loop forever... last_vibration = t # Save last trigger time # Stretch out frames if nothing has happened in a couple of seconds: - if ((t - last_vibration) > cooldown_at): + if (t - last_vibration) > cooldown_at: frame_len += 0.001 # Add 1 ms if frame_len > max_frame_len: frame_len = min_frame_len diff --git a/NeoPixel_Jewel_10_Minute_Necklace/NeoPixel_Jewel_10_Minute_Necklace.py b/NeoPixel_Jewel_10_Minute_Necklace/NeoPixel_Jewel_10_Minute_Necklace.py index 8fab2753..d5412c51 100644 --- a/NeoPixel_Jewel_10_Minute_Necklace/NeoPixel_Jewel_10_Minute_Necklace.py +++ b/NeoPixel_Jewel_10_Minute_Necklace/NeoPixel_Jewel_10_Minute_Necklace.py @@ -24,14 +24,14 @@ def wheel(pos): # The colours are a transition r - g - b - back to r. if (pos < 0) or (pos > 255): return (0, 0, 0) - if (pos < 85): + if pos < 85: return (int(pos * 3), int(255 - (pos * 3)), 0) - elif (pos < 170): + elif pos < 170: pos -= 85 return (int(255 - pos * 3), 0, int(pos * 3)) - else: - pos -= 170 - return (0, int(pos * 3), int(255 - pos * 3)) + + pos -= 170 + return (0, int(pos * 3), int(255 - pos * 3)) def rainbow_cycle(wait): @@ -45,9 +45,9 @@ def rainbow_cycle(wait): def rainbow(wait): for j in range(255): - for i in range(len(pixels)): - idx = int(i + j) - pixels[i] = wheel(idx & 255) + for index in range(len(pixels)): + idx = int(index + j) + pixels[index] = wheel(idx & 255) pixels.write() time.sleep(wait) @@ -72,26 +72,26 @@ def rainbow_hold(wait): while True: - if (mode == 0): # rainbow hold + if mode == 0: # rainbow hold rainbow_hold(0.02) time.sleep(.5) - elif (mode == 1): # rainbow cycle slow + elif mode == 1: # rainbow cycle slow rainbow_cycle_slow(0.02) time.sleep(0.05) - elif (mode == 2): # rainbow cycle fast + elif mode == 2: # rainbow cycle fast rainbow_cycle(0.005) time.sleep(0.050) t = time.monotonic() - if ((t - prevtime) > 8): # Every 8 seconds... + if (t - prevtime) > 8: # Every 8 seconds... mode += 1 # Next mode - if (mode > 2): # End of modes? + if mode > 2: # End of modes? mode = 0 # Start modes over - if (rgb_idx > 2): # reset R-->G-->B rotation + if rgb_idx > 2: # reset R-->G-->B rotation rgb_idx = 0 color = rgb_colors[rgb_idx] # next color assignment diff --git a/NeoPixel_Punk_Collar/NeoPixel_Punk_Collar.py b/NeoPixel_Punk_Collar/NeoPixel_Punk_Collar.py index 937b0b40..b5fc792f 100644 --- a/NeoPixel_Punk_Collar/NeoPixel_Punk_Collar.py +++ b/NeoPixel_Punk_Collar/NeoPixel_Punk_Collar.py @@ -24,14 +24,14 @@ def wheel(pos): # The colours are a transition r - g - b - back to r. if (pos < 0) or (pos > 255): return (0, 0, 0) - if (pos < 85): + if pos < 85: return (int(pos * 3), int(255 - (pos * 3)), 0) - elif (pos < 170): + elif pos < 170: pos -= 85 return (int(255 - pos * 3), 0, int(pos * 3)) - else: - pos -= 170 - return (0, int(pos * 3), int(255 - pos * 3)) + + pos -= 170 + return (0, int(pos * 3), int(255 - pos * 3)) def rainbow_cycle(wait): @@ -47,6 +47,7 @@ def rainbow(wait): for i in range(len(strip)): idx = int(i + j) strip[i] = wheel(idx & 255) + time.sleep(wait) while True: diff --git a/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py b/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py index 556a22a4..c230e433 100644 --- a/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py +++ b/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py @@ -3,11 +3,6 @@ import time import board import neopixel -try: - import urandom as random -except ImportError: - import random - numpix = 64 # Number of NeoPixels pixpin = board.D1 # Pin where NeoPixels are connected strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15) diff --git a/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py b/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py index fdc293d5..82d75757 100644 --- a/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py +++ b/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py @@ -3,11 +3,6 @@ import time import board import neopixel -try: - import urandom as random # for v1.0 API support -except ImportError: - import random - numpix = 64 # Number of NeoPixels pixpin = board.D1 # Pin where NeoPixels are connected strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15) diff --git a/NeoPixel_Tiara/NeoPixel_Tiara.py b/NeoPixel_Tiara/NeoPixel_Tiara.py index 93108c9a..f0fa5f01 100644 --- a/NeoPixel_Tiara/NeoPixel_Tiara.py +++ b/NeoPixel_Tiara/NeoPixel_Tiara.py @@ -19,7 +19,7 @@ colors = [ def flash_random(wait, howmany): - for k in range(howmany): + for _ in range(howmany): c = random.randint(0, len(colors) - 1) # Choose random color index j = random.randint(0, numpix - 1) # Choose random pixel diff --git a/NeoPixie_Dust_Bag/NeoPixie_Dust_Bag.py b/NeoPixie_Dust_Bag/NeoPixie_Dust_Bag.py index c902c7e8..bc208c36 100644 --- a/NeoPixie_Dust_Bag/NeoPixie_Dust_Bag.py +++ b/NeoPixie_Dust_Bag/NeoPixie_Dust_Bag.py @@ -36,27 +36,27 @@ while True: gcolor = 0 bcolor = 0 - if (showcolor == 0): # Garden PINK + if showcolor == 0: # Garden PINK rcolor = 242 gcolor = 90 bcolor = 255 - elif (showcolor == 1): # Pixie GOLD + elif showcolor == 1: # Pixie GOLD rcolor = 255 gcolor = 222 bcolor = 30 - elif (showcolor == 2): # Alchemy BLUE + elif showcolor == 2: # Alchemy BLUE rcolor = 50 gcolor = 255 bcolor = 255 - elif (showcolor == 3): # Animal ORANGE + elif showcolor == 3: # Animal ORANGE rcolor = 255 gcolor = 100 bcolor = 0 - elif (showcolor == 4): # Tinker GREEN + elif showcolor == 4: # Tinker GREEN rcolor = 0 gcolor = 255 bcolor = 40 @@ -84,17 +84,17 @@ while True: newstate = button.value # Check if state changed from high to low (button press). - if (newstate and not oldstate): + if newstate and not oldstate: # Short delay to debounce button. time.sleep(0.020) # Check if button is still low after debounce. newstate = button.value - if (newstate == False): + if not newstate: showcolor += 1 - if (showcolor > 4): + if showcolor > 4: showcolor = 0 # Set the last button state to the old state. diff --git a/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.py b/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.py index 1a8aefc9..7c9e933e 100644 --- a/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.py +++ b/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.py @@ -37,9 +37,8 @@ def wheel(pos): elif pos < 170: pos -= 85 return (int(255 - pos * 3), 0, int(pos * 3)) - else: - pos -= 170 - return (0, int(pos * 3), int(255 - pos * 3)) + pos -= 170 + return (0, int(pos * 3), int(255 - pos * 3)) def remap_range(value, leftMin, leftMax, rightMin, rightMax): diff --git a/raver_bandolier/raver_bandolier.py b/raver_bandolier/raver_bandolier.py index ef47032d..c3aa47d9 100644 --- a/raver_bandolier/raver_bandolier.py +++ b/raver_bandolier/raver_bandolier.py @@ -29,9 +29,9 @@ def wheel(pos): elif pos < 170: pos -= 85 return (int(255 - pos * 3), 0, int(pos * 3)) - else: - pos -= 170 - return (0, int(pos * 3), int(255 - pos * 3)) + + pos -= 170 + return (0, int(pos * 3), int(255 - pos * 3)) def rainbow_cycle(wait):