forked from adafruit/Adafruit_Learning_System_Guides
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request adafruit#2712 from firepixie/Rapunzel_Hair
Rapunzel Hair Code
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# SPDX-FileCopyrightText: Erin St Blaine and ChatGPT for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import time | ||
import board | ||
from adafruit_circuitplayground import cp | ||
import neopixel | ||
|
||
# Constants | ||
NUM_PIXELS_STRIP = 20 | ||
NUM_PIXELS_FACE = 10 # Number of NeoPixels on the face | ||
PIXEL_PIN_STRIP = board.A1 | ||
SOUND_THRESHOLD = 50 # Adjust this threshold based on your environment | ||
|
||
# Variables | ||
DELAY_AFTER_LIGHT_UP = 2.0 | ||
COLOR = (255, 100, 0) # Warm yellow color | ||
SPEED = 0.3 # Animation speed (adjust as needed, higher number moves more slowly) | ||
|
||
# Initialize NeoPixels on face | ||
pixels_face = cp.pixels | ||
pixels_face.brightness = 0.5 | ||
|
||
# Initialize NeoPixels on strip (A1) | ||
pixels_strip = neopixel.NeoPixel(PIXEL_PIN_STRIP, NUM_PIXELS_STRIP, brightness=0.5) | ||
|
||
# Main loop | ||
while True: | ||
# Read sound level | ||
sound_level = cp.sound_level | ||
|
||
# Debugging: Print sound level to the serial monitor | ||
print("Sound Level:", sound_level) | ||
|
||
# Check if sound threshold is reached | ||
if sound_level > SOUND_THRESHOLD: | ||
# Sequentially light up NeoPixels on the face | ||
for i in range(NUM_PIXELS_FACE): | ||
if i < len(pixels_face): | ||
pixels_face[i] = COLOR | ||
time.sleep(SPEED) # Adjust speed if needed | ||
pixels_face.show() # Show all pixels at once | ||
|
||
# Sequentially light up NeoPixels on strip (A1) | ||
for i in range(NUM_PIXELS_STRIP): | ||
if i < len(pixels_strip): | ||
pixels_strip[i] = COLOR | ||
time.sleep(SPEED) # Adjust speed if needed | ||
pixels_strip.show() # Show all pixels at once | ||
|
||
# Delay for the specified duration after lighting up all pixels | ||
time.sleep(DELAY_AFTER_LIGHT_UP) | ||
|
||
# Turn off all pixels on strip | ||
pixels_strip.fill((0, 0, 0)) | ||
pixels_strip.show() | ||
|
||
# Turn off all pixels on face | ||
pixels_face.fill((0, 0, 0)) | ||
pixels_face.show() | ||
|
||
# Add a delay to avoid rapid detection | ||
time.sleep(0.1) |