SunFounder ESP32 Starter Kit
Code
Note:
• You can open the file 5.8_pot.ino under the path of esp32-starter-kit-main\c\codes\5.8_pot.
• After selecting the board (ESP32 Dev Module) and the appropriate port, click the Upload button.
• Always displaying “Unknown COMxx”?
After the code is uploaded successfully, rotate the potentiometer and you will see the brightness of the LED change
accordingly. At the same time you can see the analog and voltage values of the potentiometer in the serial monitor.
How it works?
1. Define constants for pin connections and PWM settings.
const int potPin = 14; // Potentiometer connected to GPIO14
const int ledPin = 26; // LED connected to GPIO26
// PWM settings
const int freq = 5000; // PWM frequency
const int resolution = 12; // PWM resolution (bits)
const int channel = 0; // PWM channel
Here the PWM resolution is set to 12 bits and the range is 0-4095.
88 Chapter 1. For Arduino User