EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #416 background imageLoading...
Page #416 background image
SunFounder ESP32 Starter Kit
is associated with a specific note, and when the user touches a pin, the corresponding note is played on the passive
buzzer. The result is a simple and affordable way to enjoy the experience of playing the piano.
Wiring
Code
Note:
Open the 6.1_fruit_piano.py file located in the esp32-starter-kit-main\micropython\codes path,
or copy and paste the code into Thonny. Then, click “Run Current Script” or press F5 to execute it.
Make sure to select the “MicroPython (ESP32).COMxx” interpreter in the bottom right corner.
from machine import Pin, PWM, TouchPad
import time
# Define the touch pins and their corresponding notes
touch_pins = [4, 15, 13, 12, 14, 27, 33, 32] # Use valid touch-capable pins
notes = [262, 294, 330, 349, 392, 440, 494, 523]
# Initialize the touch sensors
touch_sensors = [TouchPad(Pin(pin)) for pin in touch_pins]
# Initialize the buzzer
(continues on next page)
410 Chapter 3. For MicroPython User

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish