From 592fb6afde63186c22f982fd52b381926498e77e Mon Sep 17 00:00:00 2001 From: Aaron Dershem Date: Mon, 14 May 2018 14:40:08 -0400 Subject: [PATCH 1/6] Pylint Clean up 3D Printed Guardian Sword --- .../3D_Printed_Guardian_Sword.py | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/3D_Printed_Guardian_Sword/3D_Printed_Guardian_Sword.py b/3D_Printed_Guardian_Sword/3D_Printed_Guardian_Sword.py index 6f999044a..8a9b15f7c 100644 --- a/3D_Printed_Guardian_Sword/3D_Printed_Guardian_Sword.py +++ b/3D_Printed_Guardian_Sword/3D_Printed_Guardian_Sword.py @@ -18,32 +18,32 @@ pixels = neopixel.NeoPixel(pin, pixel_count, brightness=1, auto_write=False) while True: - # For the first 14 pixels, make them orange, + # For the first 14 pixels, make them orange, # starting from pixel number 0. - for i in range( 0, APIXELS ): - # Set Pixels to Orange Color - pixels[i] = ( 255, 50, 0 ) + for i in range(0, APIXELS): + # Set Pixels to Orange Color + pixels[i] = (255, 50, 0) # This sends the updated pixel color to the hardware. - pixels.write() - # Delay for a period of time (in milliseconds). - time.sleep(delayval) + pixels.write() + # Delay for a period of time (in milliseconds). + time.sleep(delayval) - # Fill up 84 pixels with blue, + # Fill up 84 pixels with blue, # starting with pixel number 14. - for i in range ( 14, BPIXELS ): - # Set Pixels to Orange Color - pixels[i] = ( 0, 250, 200 ) + for i in range(14, BPIXELS): + # Set Pixels to Orange Color + pixels[i] = (0, 250, 200) # This sends the updated pixel color to the hardware. - pixels.write() - # Delay for a period of time (in milliseconds). - time.sleep(delayval) + pixels.write() + # Delay for a period of time (in milliseconds). + time.sleep(delayval) - # Fill up 9 pixels with orange, + # Fill up 9 pixels with orange, # starting from pixel number 84. - for i in range ( 84, CPIXELS ): - # Set Pixels to Orange Color - pixels[i] = ( 250, 50, 0 ) + for i in range(84, CPIXELS): + # Set Pixels to Orange Color + pixels[i] = (250, 50, 0) # This sends the updated pixel color to the hardware. - pixels.write() - # Delay for a period of time (in milliseconds). - time.sleep(delayval) + pixels.write() + # Delay for a period of time (in milliseconds). + time.sleep(delayval) From a63cfe1e1caa2ff0794bb4e551690e11da2bcb71 Mon Sep 17 00:00:00 2001 From: Aaron Dershem Date: Mon, 14 May 2018 15:24:55 -0400 Subject: [PATCH 2/6] Fixes Flake 8 issues --- .../3D_Printed_LED_Microphone_Flag.py | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/3D_Printed_LED_Microphone_Flag/3D_Printed_LED_Microphone_Flag.py b/3D_Printed_LED_Microphone_Flag/3D_Printed_LED_Microphone_Flag.py index c594fd273..5a3c1f35c 100644 --- a/3D_Printed_LED_Microphone_Flag/3D_Printed_LED_Microphone_Flag.py +++ b/3D_Printed_LED_Microphone_Flag/3D_Printed_LED_Microphone_Flag.py @@ -26,12 +26,10 @@ # Written by Paul Badger 2007 # Modified fromhere code by Greg Shakar # Ported to Circuit Python by Mikey Sklar - +import time import board import neopixel -import time from analogio import AnalogIn -import array n_pixels = 16 # Number of pixels you are using mic_pin = AnalogIn(board.A1) # Microphone is attached to this analog pin @@ -40,7 +38,8 @@ sample_window = .1 # Sample window for average level peak_hang = 24 # Time of pause before peak dot falls peak_fall = 4 # Rate of falling peak dot input_floor = 10 # Lower range of analogRead input -input_ceiling = 300 # Max range of analogRead input, the lower the value the more sensitive (1023 = max) +input_ceiling = 300 # Max range of analogRead input, the lower + # the value the more sensitive (1023 = max) peak = 16 # Peak level of column; used for falling dots sample = 0 @@ -53,11 +52,11 @@ strip = neopixel.NeoPixel(led_pin, n_pixels, brightness=1, auto_write=False) def wheel(pos): # Input a value 0 to 255 to get a color value. # The colours are a transition r - g - b - back to r. - if (pos < 0) or (pos > 255): + 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: @@ -86,28 +85,28 @@ def fscale(originalmin, originalmax, newbegin, newend, inputvalue, curve): # condition curve parameter # limit range - if (curve > 10): + if curve > 10: curve = 10 - if (curve < -10): + if curve < -10: curve = -10 - # - invert and scale - - # this seems more intuitive + # - invert and scale - + # this seems more intuitive # postive numbers give more weight to high end on output - curve = (curve * -.1) + curve = (curve * -.1) curve = pow(10, curve) # convert linear scale into lograthimic exponent for other pow function # Check for out of range inputValues - if (inputvalue < originalmin): + if inputvalue < originalmin: inputvalue = originalmin - if (inputvalue > originalmax): + if inputvalue > originalmax: inputvalue = originalmax # Zero Refference the values originalrange = originalmax - originalmin - if (newend > newbegin): + if newend > newbegin: newrange = newend - newbegin else: newrange = newbegin - newend @@ -116,50 +115,50 @@ def fscale(originalmin, originalmax, newbegin, newend, inputvalue, curve): zerorefcurval = inputvalue - originalmin normalizedcurval = zerorefcurval / originalrange # normalize to 0 - 1 float - # Check for originalMin > originalMax - # -the math for all other cases + # Check for originalMin > originalMax + # -the math for all other cases # i.e. negative numbers seems to work out fine - if (originalmin > originalmax ): - return(0) + if originalmin > originalmax: + return 0 - if (invflag == 0): + if invflag == 0: rangedvalue = (pow(normalizedcurval, curve) * newrange) + newbegin else: # invert the ranges - rangedvalue = newbegin - (pow(normalizedcurval, curve) * newrange); + rangedvalue = newbegin - (pow(normalizedcurval, curve) * newrange) - return(rangedvalue) + return rangedvalue def drawLine(fromhere, to): fromheretemp = 0 - if (fromhere > to): + if fromhere > to: fromheretemp = fromhere fromhere = to to = fromheretemp - for i in range(fromhere, to): - strip[i] = (0,0,0) + for n in range(fromhere, to): + strip[n] = (0, 0, 0) while True: time_start = time.monotonic() # current time used for sample window peaktopeak = 0 # peak-to-peak level signalmax = 0 - signalmin = 1023 + signalmin = 1023 c = 0 y = 0 # collect data for length of sample window (in seconds) - while ( ( time.monotonic() - time_start ) < sample_window): + while (time.monotonic() - time_start ) < sample_window: sample = mic_pin.value / 64 # convert to arduino 10-bit [1024] fromhere 16-bit [65536] - if (sample < 1024): # toss out spurious readings + if sample < 1024: # toss out spurious readings - if (sample > signalmax): + if sample > signalmax: signalmax = sample # save just the max levels - elif (sample < signalmin): + elif sample < signalmin: signalmin = sample # save just the min levels peaktopeak = signalmax - signalmin # max - min = peak-peak amplitude @@ -171,11 +170,11 @@ while True: # Scale the input logarithmically instead of linearly c = fscale(input_floor, input_ceiling, (n_pixels - 1), 0, peaktopeak, 2) - if (c < peak): + if c < peak: peak = c # keep dot on top dothangcount = 0 # make the dot hang before falling - if (c <= n_pixels): # fill partial column with off pixels + if c <= n_pixels: # fill partial column with off pixels drawLine(n_pixels, n_pixels - int(c)) # Set the peak dot to match the rainbow gradient @@ -184,8 +183,9 @@ while True: strip.write() # Frame based peak dot animation - if(dothangcount > peak_hang): # Peak pause length - if(++dotcount >= peak_fall): # Fall rate + if dothangcount > peak_hang: # Peak pause length + dotcount = dotcount + 1 + if dotcount >= peak_fall: # Fall rate peak += 1 dotcount = 0 else: From 3ad6fec0c750b0055a3f382afaa1eff9dc86125a Mon Sep 17 00:00:00 2001 From: Aaron Dershem Date: Mon, 14 May 2018 15:34:52 -0400 Subject: [PATCH 3/6] Fixes Flake 8 Issues --- .../3D_Printed_NeoPixel_Gas_Mask.py | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/3D_Printed_NeoPixel_Gas_Mask/3D_Printed_NeoPixel_Gas_Mask.py b/3D_Printed_NeoPixel_Gas_Mask/3D_Printed_NeoPixel_Gas_Mask.py index 99d83de1d..29227474e 100644 --- a/3D_Printed_NeoPixel_Gas_Mask/3D_Printed_NeoPixel_Gas_Mask.py +++ b/3D_Printed_NeoPixel_Gas_Mask/3D_Printed_NeoPixel_Gas_Mask.py @@ -1,55 +1,56 @@ +import time import board import neopixel -import time try: - import urandom as random # for v1.0 API support + import urandom as random # for v1.0 API support except ImportError: - import random + import random numpix = 24 # Number of NeoPixels pixpin = board.D0 # Pin where NeoPixels are connected -strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3) +strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.3) -mode = 0 # Current animation effect -offset = 0 # Position of spinner animation -color = [255, 0, 0] # RGB color - red +mode = 0 # Current animation effect +offset = 0 # Position of spinner animation +color = [255, 0, 0] # RGB color - red prevtime = time.monotonic() # Time of last animation mode switch while True: # Loop forever... - if mode == 0: # Random sparkles - lights just one LED at a time - i = random.randint(0, numpix - 1) # Choose random pixel - strip[i] = color # Set it to current color - strip.write() # Refresh LED states - # Set same pixel to "off" color now but DON'T refresh... - # it stays on for now...bot this and the next random - # pixel will be refreshed on the next pass. - strip[i] = [0,0,0] - time.sleep(0.008) # 8 millisecond delay - elif mode == 1: # Spinny wheels - # A little trick here: pixels are processed in groups of 8 - # (with 2 of 8 on at a time), NeoPixel rings are 24 pixels - # (8*3) and 16 pixels (8*2), so we can issue the same data - # to both rings and it appears correct and contiguous - # (also, the pixel order is different between the two ring - # types, so we get the reversed motion on #2 for free). - for i in range(numpix): # For each LED... - if ((offset + i) & 7) < 2: # 2 pixels out of 8... - strip[i] = color # are set to current color - else: - strip[i] = [0,0,0] # other pixels are off - strip.write() # Refresh LED states - time.sleep(0.04) # 40 millisecond delay - offset += 1 # Shift animation by 1 pixel on next frame - if offset >= 8: offset = 0 - # Additional animation modes could be added here! + if mode == 0: # Random sparkles - lights just one LED at a time + i = random.randint(0, numpix - 1) # Choose random pixel + strip[i] = color # Set it to current color + strip.write() # Refresh LED states + # Set same pixel to "off" color now but DON'T refresh... + # it stays on for now...bot this and the next random + # pixel will be refreshed on the next pass. + strip[i] = [0, 0, 0] + time.sleep(0.008) # 8 millisecond delay + elif mode == 1: # Spinny wheels + # A little trick here: pixels are processed in groups of 8 + # (with 2 of 8 on at a time), NeoPixel rings are 24 pixels + # (8*3) and 16 pixels (8*2), so we can issue the same data + # to both rings and it appears correct and contiguous + # (also, the pixel order is different between the two ring + # types, so we get the reversed motion on #2 for free). + for i in range(numpix): # For each LED... + if ((offset + i) & 7) < 2: # 2 pixels out of 8... + strip[i] = color # are set to current color + else: + strip[i] = [0, 0, 0] # other pixels are off + strip.write() # Refresh LED states + time.sleep(0.04) # 40 millisecond delay + offset += 1 # Shift animation by 1 pixel on next frame + if offset >= 8: + offset = 0 + # Additional animation modes could be added here! - t = time.monotonic() # Current time in seconds - if (t - prevtime) >= 8: # Every 8 seconds... - mode += 1 # Advance to next mode - if mode > 1: # End of modes? - mode = 0 # Start over from beginning - # Rotate color R->G->B - color = [ color[2], color[0], color[1] ] - strip.fill([0,0,0]) # Turn off all pixels - prevtime = t # Record time of last mode change + t = time.monotonic() # Current time in seconds + if (t - prevtime) >= 8: # Every 8 seconds... + mode += 1 # Advance to next mode + if mode > 1: # End of modes? + mode = 0 # Start over from beginning + # Rotate color R->G->B + color = [color[2], color[0], color[1]] + strip.fill([0, 0, 0]) # Turn off all pixels + prevtime = t # Record time of last mode change From 6769ee97ed2d2e6dc5dbdb6bb589b089f80efd12 Mon Sep 17 00:00:00 2001 From: Aaron Dershem Date: Mon, 14 May 2018 16:06:25 -0400 Subject: [PATCH 4/6] Fixes flake 8 issues --- .../3D_Printed_NeoPixel_Ring_Hair_Dress.py | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/3D_Printed_NeoPixel_Ring_Hair_Dress/3D_Printed_NeoPixel_Ring_Hair_Dress.py b/3D_Printed_NeoPixel_Ring_Hair_Dress/3D_Printed_NeoPixel_Ring_Hair_Dress.py index fc51bddcf..60fe89712 100644 --- a/3D_Printed_NeoPixel_Ring_Hair_Dress/3D_Printed_NeoPixel_Ring_Hair_Dress.py +++ b/3D_Printed_NeoPixel_Ring_Hair_Dress/3D_Printed_NeoPixel_Ring_Hair_Dress.py @@ -1,20 +1,21 @@ # # 3D_Printed_NeoPixel_Ring_Hair_Dress.py # -# this was ported to CircuitPython from the 'Gemma Hoop Animator' +# this was ported to CircuitPython from the 'Gemma Hoop Animator' # # https://github.com/HerrRausB/GemmaHoopAnimator # -# unless you # don't like the preset animations or find a +# unless you # don't like the preset animations or find a # major bug, you don't need tochange anything here # +import time import board import neopixel -import time + try: - import urandom as random # for v1.0 API support + import urandom as random # for v1.0 API support except ImportError: - import random + import random from analogio import AnalogIn # available actions @@ -65,7 +66,7 @@ curr_action = 0 curr_color_gen = COL_RANDOM idx = 0 offset = 0 -number_of_actions = 31 +number_of_actions = 31 curr_action_idx = 0 curr_color_granularity = 1 spectrum_part = 0 @@ -81,7 +82,7 @@ spectrum_part = 0 # ACT_WHEEL_ACLK anti clockwise spinning wheel # ACT_WHEEL_CLKW clockwise spinning wheel # ACT_SPARKLING_RING sparkling effect -# +# # valid color options are: # COL_RANDOM colors will be selected randomly, which might # be not very sufficient due to well known @@ -92,64 +93,63 @@ spectrum_part = 0 # action action name & action step color color change # duration color generation method duration granularity interval theactionlist = [ - [ 5, ACT_SPARKLING_RING | COL_RANDOM, 0.01, 25, 1 ], - [ 2, ACT_CYCLING_RING_CLKW | COL_RANDOM, 0.02, 1, 0.005 ], - [ 5, ACT_SPARKLING_RING | COL_RANDOM, 0.01, 25, 1 ], - [ 2, ACT_CYCLING_RING_ACLK | COL_RANDOM, 0.02, 1, 0.005 ], - [ 5, ACT_SPARKLING_RING | COL_RANDOM, 0.01, 25, 1 ], - [ 2.5, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.25, 20, 0.020 ], - [ 1, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.50, 1, 0.020 ], - [ .750, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.075, 1, 0.020 ], - [ .500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.100, 1, 0.020 ], - [ .500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.125, 1, 0.020 ], - [ .500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.150, 1, 0.050 ], - [ .500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.175, 1, 0.100 ], - [ .500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.200, 1, 0.200 ], - [ .750, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.225, 1, 0.250 ], - [ 1, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.250, 1, 0.350 ], - [ 30, ACT_SIMPLE_RING | COL_SPECTRUM, 0.050, 1, 0.010 ], - [ 2.5, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.010, 1, 0.010 ], - [ 2.5, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.015, 1, 0.020 ], - [ 2, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.025, 1, 0.030 ], - [ 1, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.050, 1, 0.040 ], - [ 1, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.075, 1, 0.040 ], - [ 1, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.100, 1, 0.050 ], - [ .500, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.125, 1, 0.060 ], - [ .500, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.125, 5, 0.050 ], - [ 1, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.100, 10, 0.040 ], - [ 1.5, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.075, 15, 0.030 ], - [ 2, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.050, 20, 0.020 ], - [ 2.5, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.025, 25, 0.010 ], - [ 3, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.010, 30, 0.005 ], - [ 5, ACT_SPARKLING_RING | COL_RANDOM, 0.010, 25, 1 ], - [ 5, ACT_NOP, 0, 0, 0 ] + [5, ACT_SPARKLING_RING | COL_RANDOM, 0.01, 25, 1 ], + [2, ACT_CYCLING_RING_CLKW | COL_RANDOM, 0.02, 1, 0.005 ], + [5, ACT_SPARKLING_RING | COL_RANDOM, 0.01, 25, 1 ], + [2, ACT_CYCLING_RING_ACLK | COL_RANDOM, 0.02, 1, 0.005 ], + [5, ACT_SPARKLING_RING | COL_RANDOM, 0.01, 25, 1 ], + [2.5, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.25, 20, 0.020 ], + [1, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.50, 1, 0.020 ], + [.750, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.075, 1, 0.020 ], + [.500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.100, 1, 0.020 ], + [.500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.125, 1, 0.020 ], + [.500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.150, 1, 0.050 ], + [.500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.175, 1, 0.100 ], + [.500, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.200, 1, 0.200 ], + [.750, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.225, 1, 0.250 ], + [1, ACT_CYCLING_RING_CLKW | COL_SPECTRUM, 0.250, 1, 0.350 ], + [30, ACT_SIMPLE_RING | COL_SPECTRUM, 0.050, 1, 0.010 ], + [2.5, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.010, 1, 0.010 ], + [2.5, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.015, 1, 0.020 ], + [2, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.025, 1, 0.030 ], + [1, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.050, 1, 0.040 ], + [1, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.075, 1, 0.040 ], + [1, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.100, 1, 0.050 ], + [.500, ACT_WHEEL_ACLK | COL_SPECTRUM, 0.125, 1, 0.060 ], + [.500, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.125, 5, 0.050 ], + [1, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.100, 10, 0.040 ], + [1.5, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.075, 15, 0.030 ], + [2, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.050, 20, 0.020 ], + [2.5, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.025, 25, 0.010 ], + [3, ACT_WHEEL_CLKW | COL_SPECTRUM, 0.010, 30, 0.005 ], + [5, ACT_SPARKLING_RING | COL_RANDOM, 0.010, 25, 1 ], + [5, ACT_NOP, 0, 0, 0] ] def nextspectrumcolor(): global spectrum_part, color_idx, curr_color_granularity, color - # spectral wipe from green to red - if (spectrum_part == 2): + if spectrum_part == 2: color = (color_idx, 0, 255-color_idx) color_idx += curr_color_granularity - if (color_idx > 255): + if color_idx > 255: spectrum_part = 0 color_idx = 0 # spectral wipe from blue to green - elif (spectrum_part == 1): + elif spectrum_part == 1: color = (0, 255 - color_idx, color_idx) color_idx += curr_color_granularity - if (color_idx > 255): + if color_idx > 255: spectrum_part = 2 color_idx = 0 # spectral wipe from red to blue - elif (spectrum_part == 0 ): + elif spectrum_part == 0: color = (255 - color_idx, color_idx, 0) color_idx += curr_color_granularity - if (color_idx > 255): + if color_idx > 255: spectrum_part = 1 color_idx = 0 @@ -162,19 +162,19 @@ def nextrandomcolor(): random_red = random.randint(0, int (256 / curr_color_granularity)) random_red *= curr_color_granularity - random_green = random.randint(0, int (256 / curr_color_granularity)) + random_green = random.randint(0, int (256 / curr_color_granularity)) random_green *= curr_color_granularity - random_blue = random.randint(0, int (256 / curr_color_granularity)) + random_blue = random.randint(0, int (256 / curr_color_granularity)) random_blue *= curr_color_granularity color = (random_red, random_green, random_blue) def nextcolor(): # save some RAM for more animation actions - if (curr_color_gen & COL_RANDOM): - nextrandomcolor() - else: + if curr_color_gen & COL_RANDOM: + nextrandomcolor() + else: nextspectrumcolor() def setup(): @@ -187,13 +187,13 @@ def setup(): # let's go! nextcolor() strip.write() - + setup() while True: # Loop forever... # do we need to load the next action? - if ( (time.monotonic() - action_timer) > curr_action_duration ): + if (time.monotonic() - action_timer) > curr_action_duration: curr_action_duration = theactionlist[curr_action_idx][action_duration] curr_action = theactionlist[curr_action_idx][action_and_color_gen] & 0x3F curr_action_step_duration = theactionlist[curr_action_idx][action_step_duration] @@ -204,36 +204,36 @@ while True: # Loop forever... # take care to rotate the action list! curr_action_idx %= number_of_actions - action_timer = time.monotonic() - + action_timer = time.monotonic() + # do we need to change to the next color? - if ((time.monotonic() - color_timer) > curr_color_interval): + if (time.monotonic() - color_timer) > curr_color_interval: nextcolor() - color_timer = time.monotonic() + color_timer = time.monotonic() # do we need to step up the current action? - if ((time.monotonic() - action_step_timer) > curr_action_step_duration): + if (time.monotonic() - action_step_timer) > curr_action_step_duration: - if (curr_action): + if curr_action: - if (curr_action == ACT_NOP): + if curr_action == ACT_NOP: # rather trivial even tho this will be repeated as long as the # NOP continues - i could have prevented it from repeating # unnecessarily, but that would mean more code and less # space for more actions within the animation for i in range(0, numpix): - strip[i] = (0,0,0) + strip[i] = (0, 0, 0) - elif (curr_action == ACT_SIMPLE_RING): + elif curr_action == ACT_SIMPLE_RING: # even more trivial - just set the new color, if there is one for i in range(0, numpix): strip[i] = color - elif ( curr_action == (ACT_CYCLING_RING_ACLK or ACT_CYCLING_RING_CLKW)): + elif curr_action == (ACT_CYCLING_RING_ACLK or ACT_CYCLING_RING_CLKW): # spin the ring clockwise or anti clockwise - if (curr_action == ACT_CYCLING_RING_ACLK): + if curr_action == ACT_CYCLING_RING_ACLK: idx += 1 - else: + else: idx -= 1 # prevent overflows or underflows @@ -246,23 +246,23 @@ while True: # Loop forever... # switch on / off the appropriate pixels according to # the current offset for idx in range(0, numpix): - if ( ((offset + idx) & 7 ) < 2 ): + if ((offset + idx) & 7) < 2: strip[idx] = color else: - strip[idx] = (0,0,0) + strip[idx] = (0, 0, 0) # advance the offset and thus, spin the wheel - if (curr_action == ACT_WHEEL_CLKW): + if curr_action == ACT_WHEEL_CLKW: offset += 1 - else: + else: offset -= 1 # prevent overflows or underflows offset %= numpix - - elif (curr_action == ACT_SPARKLING_RING): + + elif curr_action == ACT_SPARKLING_RING: # switch current pixel off - strip[idx] = (0,0,0) + strip[idx] = (0, 0, 0) # pick a new pixel idx = random.randint(0, numpix) # set new pixel to the current color From 79790d5d3de67ab2fefc532028e11c51fbb533d7 Mon Sep 17 00:00:00 2001 From: Aaron Dershem Date: Mon, 14 May 2018 16:10:20 -0400 Subject: [PATCH 5/6] Fixes flake 8 issues --- 3D_Printed_Unicorn_Horn/3D_Printed_Unicorn_Horn.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/3D_Printed_Unicorn_Horn/3D_Printed_Unicorn_Horn.py b/3D_Printed_Unicorn_Horn/3D_Printed_Unicorn_Horn.py index d9e459f0f..e07533554 100644 --- a/3D_Printed_Unicorn_Horn/3D_Printed_Unicorn_Horn.py +++ b/3D_Printed_Unicorn_Horn/3D_Printed_Unicorn_Horn.py @@ -1,7 +1,7 @@ -from digitalio import DigitalInOut, Direction -import board -import neopixel import time +from digitalio import DigitalInOut, Direction +import board +import neopixel pixpin = board.D1 numpix = 8 @@ -16,9 +16,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) - 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: From b2256e9a3b849eaa8700b351b357f3ba44856df0 Mon Sep 17 00:00:00 2001 From: Aaron Dershem Date: Mon, 14 May 2018 16:17:17 -0400 Subject: [PATCH 6/6] Fixes Flake 8 issues Adafruit LED Sequins --- Adafruit_LED_Sequins/Adafruit_LED_Sequins.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Adafruit_LED_Sequins/Adafruit_LED_Sequins.py b/Adafruit_LED_Sequins/Adafruit_LED_Sequins.py index 3eb9f9ff2..fa2da9df2 100644 --- a/Adafruit_LED_Sequins/Adafruit_LED_Sequins.py +++ b/Adafruit_LED_Sequins/Adafruit_LED_Sequins.py @@ -1,10 +1,10 @@ +import time import board import pulseio -import time from digitalio import DigitalInOut, Direction # PWM (fading) LEDs are connected on D0 (PWM not avail on D1) -pwm_leds = board.D0 +pwm_leds = board.D0 pwm = pulseio.PWMOut(pwm_leds, frequency=1000, duty_cycle=0) # digital LEDs connected on D2 @@ -18,7 +18,7 @@ counter = 0 # counter to keep track of cycles while True: # And send to LED as PWM level - pwm.duty_cycle = brightness + pwm.duty_cycle = brightness # change the brightness for next time through the loop: brightness = brightness + fade_amount @@ -26,10 +26,10 @@ while True: print(brightness) # reverse the direction of the fading at the ends of the fade: - if ( brightness <= 0 ): + if brightness <= 0: fade_amount = -fade_amount counter += 1 - elif ( brightness >= 65535 ): + elif brightness >= 65535: fade_amount = -fade_amount counter += 1 @@ -40,7 +40,7 @@ while True: # checking the modulo of the counter. # the modulo function gives you the remainder of # the division of two numbers: - if ( counter % 4 == 0 ): - digital_leds.value = True + if counter % 4 == 0: + digital_leds.value = True else: digital_leds.value = False