|
#!/usr/bin/python |
|
# CPX Light Effects program. Copyright (c) 2022 by Elk Grove Village Public Library. |
|
# Licensed under the [GNU General Public License, version 3](https://www.gnu.org/licenses/gpl-3.0.en.html). |
|
|
|
from adafruit_circuitplayground.express import cpx |
|
import time |
|
|
|
wait_time = 0.05 |
|
pixel_count = 10 |
|
|
|
def fill(color_value): |
|
for pixel in range( 0, pixel_count, 1 ): |
|
cpx.pixels[pixel] = color_value |
|
time.sleep(wait_time) |
|
time.sleep(wait_time) |
|
for pixel in range( pixel_count-1, -1, -1 ): |
|
cpx.pixels[pixel] = (0,0,0) |
|
time.sleep(wait_time) |
|
|
|
def scanner(color_value): |
|
red_value = color_value[0] |
|
green_value = color_value[1] |
|
blue_value = color_value[2] |
|
temp = round(pixel_count/2) |
|
low_r = round(red_value/255) |
|
low_g = round(green_value/255) |
|
low_b = round(blue_value/255) |
|
med_r = round(red_value/4) |
|
med_g = round(green_value/4) |
|
med_b = round(blue_value/4) |
|
for n in range (0,10,1): |
|
cpx.pixels[0] = (red_value, green_value, blue_value) |
|
cpx.pixels[5] = (red_value, green_value, blue_value) |
|
for i in range(1, temp, 1): |
|
time.sleep(wait_time) |
|
cpx.pixels[i] = (red_value, green_value, blue_value) |
|
cpx.pixels[i-1] = (low_r, low_g, low_b) |
|
cpx.pixels[i+temp] = (red_value, green_value, blue_value) |
|
cpx.pixels[i+temp-1] = (low_r, low_g, low_b) |
|
time.sleep(wait_time) |
|
cpx.pixels[temp-1] = (low_r, low_g, low_b) |
|
cpx.pixels[pixel_count-1] = (low_r, low_g, low_b) |
|
|
|
while True: |
|
if cpx.button_a: |
|
cpx.start_tone(440) |
|
fill( (0,0,255) ) # blue |
|
cpx.stop_tone() |
|
elif cpx.button_b: |
|
cpx.start_tone(880) |
|
fill( (0,255,0) ) # green |
|
cpx.stop_tone() |
|
elif cpx.touch_A1: |
|
scanner( (255,255,0) ) |
|
elif (cpx.light <= 10): |
|
for i in range(0,10,1): |
|
cpx.play_tone(1000,0.01) |
|
else: |
|
fill( (255,0,0) ) # red |