2023-01-23 12:54:34 -05:00
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
2022-07-12 22:41:36 -04:00
2021-04-12 10:06:27 -04:00
# _LEDC Fade Example_
2018-06-29 09:46:51 -04:00
(See the README.md file in the upper level 'examples' directory for more information about examples.)
2017-09-18 01:08:01 -04:00
2022-02-08 23:50:19 -05:00
This example shows how to control intensity of LEDs using selected SoC's on-board hardware LED PWM Controller module.
2017-09-18 01:08:01 -04:00
2018-06-29 09:46:51 -04:00
## How to use example
### Hardware Required
2017-09-18 01:08:01 -04:00
2022-02-08 23:50:19 -05:00
* A development board with any Espressif SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
2018-06-29 09:46:51 -04:00
* A USB cable for power supply and programming
2017-09-18 01:08:01 -04:00
2018-06-29 09:46:51 -04:00
Connect four LEDs to the following LEDC channels / individual GPIOs:
2017-09-18 01:08:01 -04:00
2022-02-08 23:50:19 -05:00
| | Channel 0 | Channel 1 | Channel 2 | Channel 3 |
| --------------- | --------- | --------- | --------- | --------- |
| ESP32 | GPIO18 | GPIO19 | GPIO4 | GPIO5 |
| All other chips | GPIO8 | GPIO9 | GPIO4 | GPIO5 |
2017-09-18 01:08:01 -04:00
2018-06-29 09:46:51 -04:00
### Configure the project
2017-09-18 01:08:01 -04:00
2018-06-29 09:46:51 -04:00
```
2019-08-01 23:31:20 -04:00
idf.py menuconfig
2018-06-29 09:46:51 -04:00
```
2017-09-18 01:08:01 -04:00
2018-06-29 09:46:51 -04:00
### Build and Flash
2017-09-18 01:08:01 -04:00
2022-02-08 23:50:19 -05:00
Build the project and flash it to the board, then run the monitor tool to view the serial output:
2021-04-12 10:06:27 -04:00
2022-02-08 23:50:19 -05:00
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
2018-06-29 09:46:51 -04:00
(To exit the serial monitor, type ``Ctrl-]``.)
2022-02-08 23:50:19 -05:00
See the [Getting Started Guide ](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html ) for full steps to configure and use ESP-IDF to build projects.
2018-06-29 09:46:51 -04:00
## Example Output
2023-01-23 12:54:34 -05:00
Running this example, you will see the four LEDs' brightness change repeatedly in the following orders
2018-06-29 09:46:51 -04:00
2023-01-23 12:54:34 -05:00
* 1: Fade up / increase intensity on the LEDs connecting to Channel 0/1; Fade down / decrease intensity on the LEDs connecting to Channel 2/3
* 2: Fade down / decrease intensity on the LEDs connecting to Channel 0/1;Fade up / increase intensity on the LEDs connecting to Channel 2/3
* 3: All LEDs keep a stable intensity
* 4: All LEDs are off
2018-06-29 09:46:51 -04:00
you can also see the following output log on the serial monitor:
```
1. LEDC fade up to duty = 4000
2. LEDC fade down to duty = 0
3. LEDC set duty = 4000 without fade
4. LEDC set duty = 0 without fade
...
```
## Troubleshooting
* Programming fail
2017-09-18 01:08:01 -04:00
2019-08-01 23:31:20 -04:00
* Hardware connection is not correct: run `idf.py -p PORT monitor` , and reboot your board to see if there are any output logs.
2018-06-29 09:46:51 -04:00
* The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
2017-09-18 01:08:01 -04:00
2021-04-12 10:06:27 -04:00
For any technical queries, please open an [issue ](https://github.com/espressif/esp-idf/issues ) on GitHub. We will get back to you soon.