Skip to content

Commit ff94835

Browse files
committed
Rapunzel Hair Code
first commit
1 parent 43a842b commit ff94835

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Rapunzel_Hair/code.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import time
2+
import board
3+
from adafruit_circuitplayground import cp
4+
import neopixel
5+
6+
# Constants
7+
NUM_PIXELS_STRIP = 20
8+
NUM_PIXELS_FACE = 10 # Number of NeoPixels on the face
9+
PIXEL_PIN_STRIP = board.A1
10+
SOUND_THRESHOLD = 50 # Adjust this threshold based on your environment
11+
12+
# Variables
13+
DELAY_AFTER_LIGHT_UP = 2.0
14+
COLOR = (255, 100, 0) # Warm yellow color
15+
SPEED = 0.2 # Animation speed (adjust as needed, higher number moves more slowly)
16+
17+
# Initialize NeoPixels on face
18+
pixels_face = cp.pixels
19+
pixels_face.brightness = 0.5
20+
21+
# Initialize NeoPixels on strip (A1)
22+
pixels_strip = neopixel.NeoPixel(PIXEL_PIN_STRIP, NUM_PIXELS_STRIP, brightness=0.5)
23+
24+
# Main loop
25+
while True:
26+
# Read sound level
27+
sound_level = cp.sound_level
28+
29+
# Debugging: Print sound level to the serial monitor
30+
print("Sound Level:", sound_level)
31+
32+
# Check if sound threshold is reached
33+
if sound_level > SOUND_THRESHOLD:
34+
# Sequentially light up NeoPixels on the face
35+
for i in range(NUM_PIXELS_FACE):
36+
if i < len(pixels_face):
37+
pixels_face[i] = COLOR
38+
time.sleep(SPEED) # Adjust speed if needed
39+
pixels_face.show() # Show all pixels at once
40+
41+
# Sequentially light up NeoPixels on strip (A1)
42+
for i in range(NUM_PIXELS_STRIP):
43+
if i < len(pixels_strip):
44+
pixels_strip[i] = COLOR
45+
time.sleep(SPEED) # Adjust speed if needed
46+
pixels_strip.show() # Show all pixels at once
47+
48+
# Delay for the specified duration after lighting up all pixels
49+
time.sleep(DELAY_AFTER_LIGHT_UP)
50+
51+
# Turn off all pixels on strip
52+
pixels_strip.fill((0, 0, 0))
53+
pixels_strip.show()
54+
55+
# Turn off all pixels on face
56+
pixels_face.fill((0, 0, 0))
57+
pixels_face.show()
58+
59+
# Add a delay to avoid rapid detection
60+
time.sleep(0.1)

0 commit comments

Comments
 (0)