1#!/usr/bin/env python
2#-------------------------------------------------------------------------------
3# qwiic_buzzer_ex8_sound_effects.py
4#
5# This example demos the sound effects included in this library.
6
7# This includes the following sound effects:
8# 0 (aka "Siren")
9# Intended to sound like a siren, starting at a low frequency, and then
10# increasing rapidly up and then back down. This sound effect does a
11# single "up and down" cycle.
12#
13# 1 (aka "3 Fast Sirens")
14# Similar to the "Siren" sound effect, only faster and goes three times.
15#
16# 2 (aka "robot saying 'Yes'")
17# Intended to sound like a robot saying the word "yes".
18# It starts at a low frequency and quickly ramps up to a high frequency,
19# then stops. This can be interpreted by most to be an affirmative
20# sound to any question you may ask your buzzing robot.
21#
22# 3 (aka "robot yelling 'YES!'" - faster)
23# Same as the "Yes" sound effect, only faster.
24# When done more quickly, it can add enthusiasm to the buzzing sound.
25#
26# 4 (aka "robot saying 'No'")
27# Intended to sound like a robot saying the word "no".
28# It starts at a high frequency and quickly ramps down to a low frequency,
29# then stops. This can be interpreted by most to be an negative
30# sound to any question you may ask your buzzing robot.
31#
32# 5 (aka "robot yelling 'NO!'" - faster)
33# Same as the "No" sound effect, only faster.
34# When done more quickly, it can add enthusiasm to the buzzing sound.
35#
36# 6 (aka "Laughing Robot")
37# Intended to sound like your robot is laughing at you.
38#
39# 7 (aka "Laughing Robot Faster")
40# Same as the "Laugh" sound effect, only faster.
41# When done more quickly, it can add enthusiasm to the buzzing sound.
42#
43# 8 (aka "Crying Robot")
44# Intended to sound like a robot is crying and sad.
45#
46# 9 (aka "Crying Robot Faster")
47# Same as the "Cry" sound effect, only faster.
48# When done more quickly, it can add enthusiasm to the buzzing sound.
49#
50# Sound effects based on the following work:
51# Jan 21st, 2020
52# Snake In A Can Controller
53# Written by: Pete Lewis, with contributions from Jeff Haas
54# A collaboration with Mario the Maker Magician
55# https://www.mariothemagician.com/
56#
57# January, 2021
58# Cry, Laugh Functions were adapted from Adafruit animal sounds
59# by Magician/hacker Jeff Haas. Thanks Jeff!!
60# https://learn.adafruit.com/adafruit-trinket-modded-stuffed-animal/animal-sounds
61#
62#-------------------------------------------------------------------------------
63# Written by SparkFun Electronics, January 2024
64#
65# This python library supports the SparkFun Electroncis Qwiic ecosystem
66#
67# More information on Qwiic is at https://www.sparkfun.com/qwiic
68#
69# Do you like this library? Help support SparkFun. Buy a board!
70#
71# https://www.sparkfun.com/products/24474
72#
73#===============================================================================
74# Copyright (c) 2023 SparkFun Electronics
75#
76# Permission is hereby granted, free of charge, to any person obtaining a copy
77# of this software and associated documentation files (the "Software"), to deal
78# in the Software without restriction, including without limitation the rights
79# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
80# copies of the Software, and to permit persons to whom the Software is
81# furnished to do so, subject to the following conditions:
82#
83# The above copyright notice and this permission notice shall be included in all
84# copies or substantial portions of the Software.
85#
86# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
87# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
89# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
90# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
91# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
92# SOFTWARE.
93#===============================================================================
94
95import qwiic_buzzer
96import sys
97import time
98
99def runExample():
100 print("\nQwiic Buzzer Example 8 - Sound Effects\n")
101
102 # Create instance of device
103 my_buzzer = qwiic_buzzer.QwiicBuzzer()
104
105 # Initialize the device
106 if my_buzzer.begin() == False:
107 print("The device isn't connected to the system. Please check your connection", \
108 file=sys.stderr)
109 return
110
111 print("\nQwiic Buzzer ready!\n")
112
113 for i in range(0,10):
114 print("\nSound Effect: ")
115 print(i)
116 my_buzzer.play_sound_effect(i, my_buzzer.VOLUME_MAX)
117 time.sleep(2)
118
119if __name__ == '__main__':
120 try:
121 runExample()
122 except (KeyboardInterrupt, SystemExit) as exErr:
123 print("\nEnding Example")
124 sys.exit(0)