Fix PEP8 compliance

This commit is contained in:
Craig Richardson 2018-05-14 22:23:44 +01:00
parent a6c15edec1
commit c9ad539ab9
7 changed files with 58 additions and 42 deletions

View file

@ -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

View file

@ -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

View file

@ -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,30 +27,33 @@ 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):
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)]
######################### MAIN LOOP ##############################
# Main Loop
i = 0
while True:
@ -74,5 +75,4 @@ while True:
# kbd.release_all()
led.value = touch2.value
i = (i + 1) % 256 # run from 0 to 255

View file

@ -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

View file

@ -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!")

View file

@ -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

View file

@ -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