2018-06-29 13:46:51 +00:00
|
|
|
# _LEDC Example_
|
|
|
|
|
|
|
|
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
2017-09-18 05:08:01 +00:00
|
|
|
|
|
|
|
This example shows how to control intensity of LEDs using ESP32's on-board hardware LED PWM Controller module.
|
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
## How to use example
|
|
|
|
|
|
|
|
### Hardware Required
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
|
|
|
|
* A USB cable for power supply and programming
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
Connect four LEDs to the following LEDC channels / individual GPIOs:
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
|ledc channel|GPIO|
|
|
|
|
|:---:|:---:|
|
|
|
|
|channel 0|GPIO18|
|
|
|
|
|channel 1|GPIO19|
|
|
|
|
|channel 2|GPIO4|
|
|
|
|
|channel 3|GPIO5|
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
### Configure the project
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
```
|
|
|
|
make menuconfig
|
|
|
|
```
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
* Set serial port under Serial Flasher Options.
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
### Build and Flash
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
Build the project and flash it to the board, then run monitor tool to view serial output:
|
|
|
|
|
|
|
|
```
|
|
|
|
make -j4 flash monitor
|
|
|
|
```
|
|
|
|
|
|
|
|
(To exit the serial monitor, type ``Ctrl-]``.)
|
|
|
|
|
|
|
|
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
|
|
|
|
|
|
|
|
## Example Output
|
|
|
|
|
|
|
|
Running this example, you will see each ledc's brightness changes differently
|
|
|
|
|
|
|
|
* LEDC 1: Fade up / increase intensity
|
|
|
|
* LEDC 2: Fade down / decrease intensity
|
|
|
|
* LEDC 3: Keep a stable intensity
|
|
|
|
* LEDC 4: LED is not on
|
|
|
|
|
|
|
|
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 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00:00
|
|
|
* Hardware connection is not correct: run `make monitor`, and reboot your board to see if there are any output logs.
|
|
|
|
* The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
|
2017-09-18 05:08:01 +00:00
|
|
|
|
2018-06-29 13:46:51 +00: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.
|