Skip to content

Commit 07ade01

Browse files
committed
first commit doorbell
1 parent a544133 commit 07ade01

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# SPDX-FileCopyrightText: Animated Eyeball Doorbell 2021 John Park for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
# Feather RP2040 + Crickit to control Gemmy Animated Eyeball Doorbell
4+
import time
5+
import board
6+
import audiomp3
7+
import audiopwmio
8+
import random
9+
from adafruit_crickit import crickit
10+
11+
ss = crickit.seesaw # Crickit seesaw setup
12+
13+
button = crickit.SIGNAL1 # momentary switch to trigger animation
14+
ss.pin_mode(button, ss.INPUT_PULLUP)
15+
16+
LED = crickit.SIGNAL4 # standard LED for eyeball lighting
17+
ss.pin_mode(LED, ss.OUTPUT)
18+
19+
attract_switch = crickit.SIGNAL8 # attract mode switch or jumper
20+
ss.pin_mode(attract_switch, ss.INPUT_PULLUP)
21+
22+
audio = audiopwmio.PWMAudioOut(board.A0) # Feather outputs this pin to Crickit amplifier
23+
audio_files = [ # use your own mono .mp3 files
24+
"phrase_01.mp3",
25+
"phrase_02.mp3",
26+
"phrase_03.mp3"
27+
]
28+
current_audio_file = 0
29+
30+
# two motors
31+
motor_eye = crickit.dc_motor_1
32+
motor_lid = crickit.dc_motor_2
33+
34+
def open_lid():
35+
motor_lid.throttle = 1 # full speed open
36+
time.sleep(0.25)
37+
motor_lid.throttle = 0 # hold
38+
39+
def close_lid():
40+
motor_lid.throttle = -1 # full speed closed
41+
time.sleep(0.25)
42+
motor_lid.throttle = 0
43+
44+
def blink(times):
45+
for _ in range(times):
46+
ss.digital_write(LED, True)
47+
time.sleep(0.1)
48+
ss.digital_write(LED, False)
49+
time.sleep(0.1)
50+
51+
def eye_look():
52+
motor_eye.throttle = random.uniform(0.6, 1.0)
53+
time.sleep(random.random()) # 0 to 1.0 seconds
54+
motor_eye.throttle = 0
55+
time.sleep(random.random())
56+
motor_eye.throttle = random.uniform(-1.0, -0.6)
57+
time.sleep(random.random())
58+
motor_eye.throttle = 0
59+
time.sleep(random.random())
60+
61+
62+
63+
while True:
64+
if ss.digital_read(attract_switch): # regular mode, attrack switch not closed/shorted
65+
if not ss.digital_read(button): # button has been pressed
66+
decoder = audiomp3.MP3Decoder(open("ring.mp3", "rb"))
67+
audio.play(decoder)
68+
while audio.playing:
69+
pass
70+
open_lid()
71+
blink(3)
72+
ss.digital_write(LED, True) # light the eye
73+
decoder = audiomp3.MP3Decoder(open(audio_files[current_audio_file], "rb"))
74+
audio.play(decoder)
75+
while audio.playing:
76+
eye_look()
77+
motor_eye.throttle = 0 # audio is finished, pause the eye
78+
blink(5)
79+
close_lid()
80+
current_audio_file = ((current_audio_file + 1) % (len(audio_files))) # go to next file
81+
82+
else: # attract mode
83+
open_lid()
84+
blink(3)
85+
ss.digital_write(LED, True)
86+
for _ in range(4):
87+
eye_look()
88+
time.sleep(1)
89+
blink(5)
90+
close_lid()
91+
time.sleep(random.randint(2, 8))
52.9 KB
Binary file not shown.
50.2 KB
Binary file not shown.
50.2 KB
Binary file not shown.
8.11 KB
Binary file not shown.

0 commit comments

Comments
 (0)