From df581b6d7fd489f65fe4076d49fad8a9556c183b Mon Sep 17 00:00:00 2001 From: Craig Richardson Date: Mon, 14 May 2018 19:59:12 +0100 Subject: [PATCH] Fix Flake8 issues --- Introducing_Gemma_M0/Gemma_HIDkeyboard.py | 2 +- Introducing_Gemma_M0/Gemma_NeoPixel.py | 4 ++-- Introducing_Gemma_M0/Gemma_UART.py | 4 ++-- .../Kaleidoscope_Eyes_NeoPixel_LED_Goggles.py | 19 +++++++------------ .../Larson_Scanner_Shades.py | 8 ++++---- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Introducing_Gemma_M0/Gemma_HIDkeyboard.py b/Introducing_Gemma_M0/Gemma_HIDkeyboard.py index 0bfa30d4..52aa9cab 100644 --- a/Introducing_Gemma_M0/Gemma_HIDkeyboard.py +++ b/Introducing_Gemma_M0/Gemma_HIDkeyboard.py @@ -51,7 +51,7 @@ while True: pass # wait for it to be released! # type the keycode or string k = buttonkeys[i] # get the corresp. keycode/str - if type(k) is str: + if isinstance(k, str): layout.write(k) else: kbd.press(controlkey, k) # press... diff --git a/Introducing_Gemma_M0/Gemma_NeoPixel.py b/Introducing_Gemma_M0/Gemma_NeoPixel.py index 6f61a7fd..863abb2f 100644 --- a/Introducing_Gemma_M0/Gemma_NeoPixel.py +++ b/Introducing_Gemma_M0/Gemma_NeoPixel.py @@ -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: diff --git a/Introducing_Gemma_M0/Gemma_UART.py b/Introducing_Gemma_M0/Gemma_UART.py index f33d4566..b5112051 100644 --- a/Introducing_Gemma_M0/Gemma_UART.py +++ b/Introducing_Gemma_M0/Gemma_UART.py @@ -1,8 +1,8 @@ # Gemma IO demo - USB/Serial echo import busio -from board import * -from digitalio import * +from board import D0, D2, D13 +from digitalio import DigitalInOut, Direction led = DigitalInOut(D13) led.direction = Direction.OUTPUT diff --git a/Kaleidoscope_Eyes_NeoPixel_LED_Goggles/Kaleidoscope_Eyes_NeoPixel_LED_Goggles.py b/Kaleidoscope_Eyes_NeoPixel_LED_Goggles/Kaleidoscope_Eyes_NeoPixel_LED_Goggles.py index 03626c93..6bd075ec 100644 --- a/Kaleidoscope_Eyes_NeoPixel_LED_Goggles/Kaleidoscope_Eyes_NeoPixel_LED_Goggles.py +++ b/Kaleidoscope_Eyes_NeoPixel_LED_Goggles/Kaleidoscope_Eyes_NeoPixel_LED_Goggles.py @@ -27,19 +27,14 @@ prevtime = 0 pixels = neopixel.NeoPixel(pixpin, numpix, brightness=.3, auto_write=False) - -def setup(): - prevtime = time.monotonic() - - -setup() +prevtime = time.monotonic() while True: i = 0 t = 0 # Random sparks - just one LED on at a time! - if (mode == 0): + if mode == 0: i = random.randint(0, (numpix - 1)) pixels[i] = color pixels.write() @@ -47,12 +42,12 @@ while True: pixels[i] = (0, 0, 0) # Spinny wheels (8 LEDs on at a time) - elif (mode == 1): + elif mode == 1: for i in range(0, numpix): c = 0 # 4 pixels on... - if (((offset + i) & 7) < 2): + if ((offset + i) & 7) < 2: c = color pixels[i] = c # First eye @@ -64,12 +59,12 @@ while True: t = time.monotonic() - if ((t - prevtime) > 8): # Every 8 seconds... + if (t - prevtime) > 8: # Every 8 seconds... mode += 1 # Next mode - if (mode > 1): # End of modes? + if mode > 1: # 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/Larson_Scanner_Shades/Larson_Scanner_Shades.py b/Larson_Scanner_Shades/Larson_Scanner_Shades.py index e75881e8..d55638c5 100644 --- a/Larson_Scanner_Shades/Larson_Scanner_Shades.py +++ b/Larson_Scanner_Shades/Larson_Scanner_Shades.py @@ -15,7 +15,7 @@ while True: strip[pos] = ([255, 48, 0]) # brightest strip[pos + 1] = ([128, 0, 0]) # Medium red - if ((pos + 2) < numpix): + if (pos + 2) < numpix: # Dark red, do not exceed number of pixels strip[pos + 2] = ([16, 0, 0]) @@ -26,14 +26,14 @@ while True: # it's easier to erase it all and draw a new one next time. for j in range(-2, 2): strip[pos + j] = (0, 0, 0) - if ((pos + 2) < numpix): + if (pos + 2) < numpix: strip[pos + 2] = (0, 0, 0) # Bounce off ends of strip pos += direction - if (pos < 0): + if pos < 0: pos = 1 direction = -direction - elif (pos >= (numpix - 1)): + elif pos >= (numpix - 1): pos = numpix - 2 direction = -direction