added speed adjustment to CPX buttons

This commit is contained in:
John Edgar Park 2018-08-30 15:05:11 -07:00
parent eb02e8ba40
commit c047b78081

View file

@ -1,5 +1,8 @@
"""Circuit Playground Express Light Paintbrush""" """Circuit Playground Express Light Paintbrush"""
# Single images only. Filename and speed are set in code, # Single images only. Filename is set in code,
# CPX buttons A&B are used to increase and decrease playback speed
# Touch pad A5 to trigger playback in one-shot mode
# Switch on CPX goes from one-shot to looping mode, requires reset
# images should be 30px high, up to 100px wide, 24-bit .bmp files # images should be 30px high, up to 100px wide, 24-bit .bmp files
import gc import gc
@ -7,6 +10,7 @@ import time
import board import board
import touchio import touchio
import digitalio import digitalio
from digitalio import DigitalInOut, Direction, Pull
from neopixel_write import neopixel_write from neopixel_write import neopixel_write
# uncomment one line only here to select bitmap # uncomment one line only here to select bitmap
@ -30,7 +34,8 @@ FILENAME = "bats.bmp" # BMP file to load from flash filesystem
#FILENAME = "minerva.bmp" #FILENAME = "minerva.bmp"
TOUCH = touchio.TouchIn(board.A5) # capacitive touch pad TOUCH = touchio.TouchIn(board.A5) # capacitive touch pad
SPEED = 50000 SPEED = 10000
SPEED_ADJUST = 2500 # This value changes the increment for button speed adjustments
BRIGHTNESS = 1.0 # Set brightness here, NOT in NeoPixel constructor BRIGHTNESS = 1.0 # Set brightness here, NOT in NeoPixel constructor
GAMMA = 2.7 # Adjusts perceived brighthess linearity GAMMA = 2.7 # Adjusts perceived brighthess linearity
NUM_PIXELS = 30 # NeoPixel strip length (in pixels) NUM_PIXELS = 30 # NeoPixel strip length (in pixels)
@ -38,6 +43,31 @@ NEOPIXEL_PIN = board.A1 # Pin where NeoPixels are connected
DELAY_TIME = 0.01 # Timer delay before it starts DELAY_TIME = 0.01 # Timer delay before it starts
LOOP = False # Set to True for looping LOOP = False # Set to True for looping
# button setup
button_a = DigitalInOut(board.BUTTON_A)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN
button_b = DigitalInOut(board.BUTTON_B)
button_b.direction = Direction.INPUT
button_b.pull = Pull.DOWN
# switch setup
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
#status led setup
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
if switch.value:
LOOP = True
else:
LOOP = False
# Enable NeoPixel pin as output and clear the strip # Enable NeoPixel pin as output and clear the strip
NEOPIXEL_PIN = digitalio.DigitalInOut(NEOPIXEL_PIN) NEOPIXEL_PIN = digitalio.DigitalInOut(NEOPIXEL_PIN)
NEOPIXEL_PIN.direction = digitalio.Direction.OUTPUT NEOPIXEL_PIN.direction = digitalio.Direction.OUTPUT
@ -144,14 +174,34 @@ print("Mem free:", gc.mem_free())
COLUMN_DELAY = SPEED / 65535.0 / 10.0 # 0.0 to 0.1 seconds COLUMN_DELAY = SPEED / 65535.0 / 10.0 # 0.0 to 0.1 seconds
# print(COLUMN_DELAY) # print(COLUMN_DELAY)
led.value = True
while LOOP: while LOOP:
for COLUMN in COLUMNS: for COLUMN in COLUMNS:
neopixel_write(NEOPIXEL_PIN, COLUMN) neopixel_write(NEOPIXEL_PIN, COLUMN)
time.sleep(COLUMN_DELAY) time.sleep(COLUMN_DELAY)
while True: while True:
# Wait for touch pad input: # Wait for touch pad input:
# buttons increase and decrease speed of playback
while not TOUCH.value: while not TOUCH.value:
if button_a.value:
if SPEED >= SPEED_ADJUST:
led.value = False
SPEED = SPEED - SPEED_ADJUST
COLUMN_DELAY = SPEED / 65535.0 / 10.0 # 0.0 to 0.1 seconds
time.sleep(0.25) #debounce
led.value = True
# print(SPEED)
if button_b.value:
if SPEED < 100000:
led.value = False
SPEED = SPEED + SPEED_ADJUST
COLUMN_DELAY = SPEED / 65535.0 / 10.0 # 0.0 to 0.1 seconds
time.sleep(0.25) #debounce
led.value = True
# print(SPEED)
continue continue
time.sleep(DELAY_TIME) time.sleep(DELAY_TIME)