From c9ad539ab919a65202e4a0642ae9c1d6e2d1c77c Mon Sep 17 00:00:00 2001 From: Craig Richardson Date: Mon, 14 May 2018 22:23:44 +0100 Subject: [PATCH] Fix PEP8 compliance --- .../CPX_Left_Rotation_State_Machine.py | 11 +++- .../CPX_Spoka_Motion_Lamp.py | 12 +++- Introducing_Gemma_M0/Default Files/main.py | 60 +++++++++---------- Introducing_Trinket_M0/Trinket_UART.py | 2 +- LED_Trampoline/LED_Trampoline.py | 5 +- .../HSV_FancyLED_NeoPixel_Dailer.py | 5 +- NeoPixel_Dialer/RGB_NeoPixel_Dialer.py | 5 +- 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/Hacking_Ikea_Lamps_With_CPX/CPX_Left_Rotation_State_Machine.py b/Hacking_Ikea_Lamps_With_CPX/CPX_Left_Rotation_State_Machine.py index 58f021d8d..3b79994a7 100644 --- a/Hacking_Ikea_Lamps_With_CPX/CPX_Left_Rotation_State_Machine.py +++ b/Hacking_Ikea_Lamps_With_CPX/CPX_Left_Rotation_State_Machine.py @@ -7,11 +7,18 @@ from adafruit_circuitplayground.express import cpx def upright(x, y, z): - return abs(x) < accel_threshold and abs(y) < accel_threshold and abs(9.8 - z) < accel_threshold + x_up = abs(x) < accel_threshold + y_up = abs(x) < accel_threshold + z_up = abs(9.8 - z) < accel_threshold + return x_up and y_up and z_up def left_side(x, y, z): - return abs(9.8 - x) < accel_threshold and abs(y) < accel_threshold and abs(z) < accel_threshold + x_side = abs(9.8 - x) < accel_threshold + y_side = abs(y) < accel_threshold + z_side = abs(z) < accel_threshold + + return x_side and y_side and z_side state = None diff --git a/Hacking_Ikea_Lamps_With_CPX/CPX_Spoka_Motion_Lamp.py b/Hacking_Ikea_Lamps_With_CPX/CPX_Spoka_Motion_Lamp.py index 2684e3c69..00ee9791f 100755 --- a/Hacking_Ikea_Lamps_With_CPX/CPX_Spoka_Motion_Lamp.py +++ b/Hacking_Ikea_Lamps_With_CPX/CPX_Spoka_Motion_Lamp.py @@ -19,15 +19,21 @@ def wheel(pos): # pylint: disable=redefined-outer-name def upright(x, y, z): - return abs(x) < accel_threshold and abs(y) < accel_threshold and abs(9.8 - z) < accel_threshold + return abs(x) < accel_threshold \ + and abs(y) < accel_threshold \ + and abs(9.8 - z) < accel_threshold def right_side(x, y, z): - return abs(-9.8 - x) < accel_threshold and abs(y) < accel_threshold and abs(z) < accel_threshold + return abs(-9.8 - x) < accel_threshold \ + and abs(y) < accel_threshold \ + and abs(z) < accel_threshold def left_side(x, y, z): - return abs(9.8 - x) < accel_threshold and abs(y) < accel_threshold and abs(z) < accel_threshold + return abs(9.8 - x) < accel_threshold \ + and abs(y) < accel_threshold \ + and abs(z) < accel_threshold # pylint: enable=redefined-outer-name diff --git a/Introducing_Gemma_M0/Default Files/main.py b/Introducing_Gemma_M0/Default Files/main.py index 9c729ba00..ee5f27f79 100644 --- a/Introducing_Gemma_M0/Default Files/main.py +++ b/Introducing_Gemma_M0/Default Files/main.py @@ -1,14 +1,12 @@ # Gemma IO demo # Welcome to CircuitPython 2.0.0 :) -import board -import time -from digitalio import DigitalInOut, Direction, Pull -from analogio import AnalogIn, AnalogOut -from touchio import TouchIn -from adafruit_hid.keyboard import Keyboard -from adafruit_hid.keycode import Keycode import adafruit_dotstar as dotstar +import board +from adafruit_hid.keyboard import Keyboard +from analogio import AnalogIn, AnalogOut +from digitalio import DigitalInOut, Direction +from touchio import TouchIn # One pixel connected internally! dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) @@ -29,50 +27,52 @@ touch2 = TouchIn(board.A2) # Used if we do HID output, see below kbd = Keyboard() -######################### HELPERS ############################## + +# Helpers # Helper to convert analog input to voltage def getVoltage(pin): return (pin.value * 3.3) / 65536 + # Helper to give us a nice color swirl 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): + if pos < 0: return [0, 0, 0] - if (pos > 255): + if pos > 255: return [0, 0, 0] - if (pos < 85): - return [int(pos * 3), int(255 - (pos*3)), 0] - elif (pos < 170): + if pos < 85: + return [int(pos * 3), int(255 - (pos * 3)), 0] + elif pos < 170: pos -= 85 - return [int(255 - pos*3), 0, int(pos*3)] + return [int(255 - pos * 3), 0, int(pos * 3)] else: pos -= 170 - return [0, int(pos*3), int(255 - pos*3)] + return [0, int(pos * 3), int(255 - pos * 3)] -######################### MAIN LOOP ############################## + +# Main Loop i = 0 while True: - # spin internal LED around! - dot[0] = wheel(i) - dot.show() + # spin internal LED around! + dot[0] = wheel(i) + dot.show() - # set analog output to 0-3.3V (0-65535 in increments) - aout.value = i * 256 + # set analog output to 0-3.3V (0-65535 in increments) + aout.value = i * 256 - # Read analog voltage on A1 - print("A1: %0.2f" % getVoltage(analog1in)) + # Read analog voltage on A1 + print("A1: %0.2f" % getVoltage(analog1in)) - # use A2 as capacitive touch to turn on internal LED - if touch2.value: + # use A2 as capacitive touch to turn on internal LED + if touch2.value: print("A2 touched!") # optional! uncomment below & save to have it sent a keypress - #kbd.press(Keycode.A) - #kbd.release_all() - led.value = touch2.value + # kbd.press(Keycode.A) + # kbd.release_all() + led.value = touch2.value - - i = (i+1) % 256 # run from 0 to 255 + i = (i + 1) % 256 # run from 0 to 255 diff --git a/Introducing_Trinket_M0/Trinket_UART.py b/Introducing_Trinket_M0/Trinket_UART.py index 3f1cf3d82..442631755 100644 --- a/Introducing_Trinket_M0/Trinket_UART.py +++ b/Introducing_Trinket_M0/Trinket_UART.py @@ -14,7 +14,7 @@ while True: data = uart.read(32) # read up to 32 bytes # print(data) # this is a bytearray type - if data != None: + if data is not None: led.value = True # convert bytearray to string diff --git a/LED_Trampoline/LED_Trampoline.py b/LED_Trampoline/LED_Trampoline.py index 42406147b..cf78455ea 100644 --- a/LED_Trampoline/LED_Trampoline.py +++ b/LED_Trampoline/LED_Trampoline.py @@ -9,7 +9,7 @@ pixel_pin = board.D10 # The pin the NeoPixels are connected to button_switch_pin = board.D9 # Pin button is attached to vibration_switch_pin = board.D7 # Pin vibration switch is attached to. pixel_count = 40 # Number of pixels in your strip -chase_color_duration = 3 # Time in seconds each color lasts in the color chase mode +chase_color_duration = 3 # Seconds each color lasts in the color chase mode pixels = neopixel.NeoPixel(pixel_pin, pixel_count, brightness=.4, auto_write=False) @@ -122,7 +122,8 @@ 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/NeoPixel_Dialer/HSV_FancyLED_NeoPixel_Dailer.py b/NeoPixel_Dialer/HSV_FancyLED_NeoPixel_Dailer.py index 5578c2e54..8378b7fa9 100644 --- a/NeoPixel_Dialer/HSV_FancyLED_NeoPixel_Dailer.py +++ b/NeoPixel_Dialer/HSV_FancyLED_NeoPixel_Dailer.py @@ -16,8 +16,9 @@ lcd_d4 = digitalio.DigitalInOut(board.D9) lcd_columns = 16 lcd_rows = 2 -lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, - lcd_d7, lcd_columns, lcd_rows) +lcd = adafruit_character_lcd.Character_LCD( + lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows +) potH = AnalogIn(board.A0) # pot for hue potS = AnalogIn(board.A1) # pot for saturation diff --git a/NeoPixel_Dialer/RGB_NeoPixel_Dialer.py b/NeoPixel_Dialer/RGB_NeoPixel_Dialer.py index 99b85f864..9f27de529 100644 --- a/NeoPixel_Dialer/RGB_NeoPixel_Dialer.py +++ b/NeoPixel_Dialer/RGB_NeoPixel_Dialer.py @@ -16,8 +16,9 @@ lcd_d4 = digitalio.DigitalInOut(board.D9) lcd_columns = 16 lcd_rows = 2 -lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, - lcd_d7, lcd_columns, lcd_rows) +lcd = adafruit_character_lcd.Character_LCD( + lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows +) potR = AnalogIn(board.A0) # pot pin for R val potG = AnalogIn(board.A1) # pot pin for G val