Fix PEP8 compliance
This commit is contained in:
parent
a6c15edec1
commit
c9ad539ab9
7 changed files with 58 additions and 42 deletions
|
|
@ -7,11 +7,18 @@ from adafruit_circuitplayground.express import cpx
|
||||||
|
|
||||||
|
|
||||||
def upright(x, y, z):
|
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):
|
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
|
state = None
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,21 @@ def wheel(pos):
|
||||||
|
|
||||||
# pylint: disable=redefined-outer-name
|
# pylint: disable=redefined-outer-name
|
||||||
def upright(x, y, z):
|
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):
|
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):
|
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
|
# pylint: enable=redefined-outer-name
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
# Gemma IO demo
|
# Gemma IO demo
|
||||||
# Welcome to CircuitPython 2.0.0 :)
|
# 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 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!
|
# One pixel connected internally!
|
||||||
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
|
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
|
# Used if we do HID output, see below
|
||||||
kbd = Keyboard()
|
kbd = Keyboard()
|
||||||
|
|
||||||
######################### HELPERS ##############################
|
|
||||||
|
# Helpers
|
||||||
|
|
||||||
# Helper to convert analog input to voltage
|
# Helper to convert analog input to voltage
|
||||||
def getVoltage(pin):
|
def getVoltage(pin):
|
||||||
return (pin.value * 3.3) / 65536
|
return (pin.value * 3.3) / 65536
|
||||||
|
|
||||||
|
|
||||||
# Helper to give us a nice color swirl
|
# Helper to give us a nice color swirl
|
||||||
def wheel(pos):
|
def wheel(pos):
|
||||||
# Input a value 0 to 255 to get a color value.
|
# Input a value 0 to 255 to get a color value.
|
||||||
# The colours are a transition r - g - b - back to r.
|
# The colours are a transition r - g - b - back to r.
|
||||||
if (pos < 0):
|
if pos < 0:
|
||||||
return [0, 0, 0]
|
return [0, 0, 0]
|
||||||
if (pos > 255):
|
if pos > 255:
|
||||||
return [0, 0, 0]
|
return [0, 0, 0]
|
||||||
if (pos < 85):
|
if pos < 85:
|
||||||
return [int(pos * 3), int(255 - (pos*3)), 0]
|
return [int(pos * 3), int(255 - (pos * 3)), 0]
|
||||||
elif (pos < 170):
|
elif pos < 170:
|
||||||
pos -= 85
|
pos -= 85
|
||||||
return [int(255 - pos*3), 0, int(pos*3)]
|
return [int(255 - pos * 3), 0, int(pos * 3)]
|
||||||
else:
|
else:
|
||||||
pos -= 170
|
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
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
# spin internal LED around!
|
# spin internal LED around!
|
||||||
dot[0] = wheel(i)
|
dot[0] = wheel(i)
|
||||||
dot.show()
|
dot.show()
|
||||||
|
|
||||||
# set analog output to 0-3.3V (0-65535 in increments)
|
# set analog output to 0-3.3V (0-65535 in increments)
|
||||||
aout.value = i * 256
|
aout.value = i * 256
|
||||||
|
|
||||||
# Read analog voltage on A1
|
# Read analog voltage on A1
|
||||||
print("A1: %0.2f" % getVoltage(analog1in))
|
print("A1: %0.2f" % getVoltage(analog1in))
|
||||||
|
|
||||||
# use A2 as capacitive touch to turn on internal LED
|
# use A2 as capacitive touch to turn on internal LED
|
||||||
if touch2.value:
|
if touch2.value:
|
||||||
print("A2 touched!")
|
print("A2 touched!")
|
||||||
# optional! uncomment below & save to have it sent a keypress
|
# optional! uncomment below & save to have it sent a keypress
|
||||||
#kbd.press(Keycode.A)
|
# kbd.press(Keycode.A)
|
||||||
#kbd.release_all()
|
# kbd.release_all()
|
||||||
led.value = touch2.value
|
led.value = touch2.value
|
||||||
|
|
||||||
|
i = (i + 1) % 256 # run from 0 to 255
|
||||||
i = (i+1) % 256 # run from 0 to 255
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ while True:
|
||||||
data = uart.read(32) # read up to 32 bytes
|
data = uart.read(32) # read up to 32 bytes
|
||||||
# print(data) # this is a bytearray type
|
# print(data) # this is a bytearray type
|
||||||
|
|
||||||
if data != None:
|
if data is not None:
|
||||||
led.value = True
|
led.value = True
|
||||||
|
|
||||||
# convert bytearray to string
|
# convert bytearray to string
|
||||||
|
|
|
||||||
|
|
@ -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
|
button_switch_pin = board.D9 # Pin button is attached to
|
||||||
vibration_switch_pin = board.D7 # Pin vibration switch is attached to.
|
vibration_switch_pin = board.D7 # Pin vibration switch is attached to.
|
||||||
pixel_count = 40 # Number of pixels in your strip
|
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,
|
pixels = neopixel.NeoPixel(pixel_pin, pixel_count,
|
||||||
brightness=.4, auto_write=False)
|
brightness=.4, auto_write=False)
|
||||||
|
|
@ -122,7 +122,8 @@ while True:
|
||||||
if mode == 1 and not vibration_switch.value:
|
if mode == 1 and not vibration_switch.value:
|
||||||
print("Sparkle mode activate!")
|
print("Sparkle mode activate!")
|
||||||
pixels.brightness = 1
|
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])
|
sparkle_code(sparkle_color_list[sparkle_color_index])
|
||||||
if mode == 2 and not vibration_switch.value:
|
if mode == 2 and not vibration_switch.value:
|
||||||
print("Chase mode activate!")
|
print("Chase mode activate!")
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ lcd_d4 = digitalio.DigitalInOut(board.D9)
|
||||||
lcd_columns = 16
|
lcd_columns = 16
|
||||||
lcd_rows = 2
|
lcd_rows = 2
|
||||||
|
|
||||||
lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6,
|
lcd = adafruit_character_lcd.Character_LCD(
|
||||||
lcd_d7, lcd_columns, lcd_rows)
|
lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows
|
||||||
|
)
|
||||||
|
|
||||||
potH = AnalogIn(board.A0) # pot for hue
|
potH = AnalogIn(board.A0) # pot for hue
|
||||||
potS = AnalogIn(board.A1) # pot for saturation
|
potS = AnalogIn(board.A1) # pot for saturation
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ lcd_d4 = digitalio.DigitalInOut(board.D9)
|
||||||
lcd_columns = 16
|
lcd_columns = 16
|
||||||
lcd_rows = 2
|
lcd_rows = 2
|
||||||
|
|
||||||
lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6,
|
lcd = adafruit_character_lcd.Character_LCD(
|
||||||
lcd_d7, lcd_columns, lcd_rows)
|
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
|
potR = AnalogIn(board.A0) # pot pin for R val
|
||||||
potG = AnalogIn(board.A1) # pot pin for G val
|
potG = AnalogIn(board.A1) # pot pin for G val
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue