SunFounder ESP32 Starter Kit
Code
Note:
• You can open the file 6.1_fruit_piano.ino under the path of esp32-starter-kit-main\c\codes\6.
1_fruit_piano directly.
• Or copy this code into Arduino IDE.
You can connect fruits to these ESP32 pins: 4, 15, 13, 12, 14, 27, 33, 32.
When the script runs, touching these fruits will play the notes C, D, E, F, G, A, B and C5.
How it works?
• touchRead(uint8_t pin);
This function gets the touch sensor data. Each touch sensor has a counter to count the number of
charge/discharge cycles. When the pad is touched, the value in the counter will change because of
the larger equivalent capacitance. The change of the data determines if the pad has been touched or
not.
– pin GPIO pin to read TOUCH value
This function returns a value between 0 and 4095, with a lower value indicating a stronger touch input.
Note: threshold needs to be adjusted based on the conductivity of different fruits.
110 Chapter 1. For Arduino User