Created
March 16, 2021 00:29
-
-
Save estranged42/e392fa9f293d1eda6db62d50192128f9 to your computer and use it in GitHub Desktop.
Basic Piezo buzzer with 6 notes on an Adafruit QT Py
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
# Uses a basic piezo buzzer to make tones: https://www.adafruit.com/product/160 | |
# Adapted from https://learn.adafruit.com/using-piezo-buzzers-with-circuitpython-arduino/circuitpython | |
# QT Py can do capacitive touch sensing on 6 pins, so we can easily play 6 notes | |
# https://learn.adafruit.com/adafruit-qt-py/pinouts | |
import board | |
import simpleio | |
import touchio | |
# Define pin connected to piezo buzzer. | |
PIEZO_PIN = board.D8 | |
# Define a list of tones/music notes to play. | |
TONE_FREQ = [ 262, # C4 | |
294, # D4 | |
330, # E4 | |
349, # F4 | |
392, # G4 | |
440, # A4 | |
494 ] # B4 | |
touches = [] | |
for pin in (board.A0, board.A1, board.A2, board.A3, board.TX, board.RX): | |
touches.append(touchio.TouchIn(pin)) | |
while True: | |
for i in range(len(touches)): | |
if touches[i].raw_value > 2500: | |
simpleio.tone(PIEZO_PIN, TONE_FREQ[i], duration=0.5) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment