roo_blink
API Documentation for roo_blink
Loading...
Searching...
No Matches
led_esp32.h
Go to the documentation of this file.
1#pragma once
2
4
5#if defined(ESP32)
6
7#include "driver/ledc.h"
8
9namespace roo_blink {
10namespace esp32 {
11
12/// Monochrome LED on a GPIO pin using ESP32 LEDC PWM for brightness control.
13class GpioLed : public ::roo_blink::Led {
14 public:
15 /// Polarity mode for the LED connection.
16 enum Mode { ON_HIGH, ON_LOW };
17
18 /// Constructs a GpioLed connected to the specified GPIO pin.
19 ///
20 /// The pin is expected to be connected to the LED anode if mode is ON_HIGH
21 /// (the default), or to the LED cathode if mode is ON_LOW.
22 ///
23 /// If provided, the specified LEDC timer and channel will be used to
24 /// control the LED brightness. The default timer and channel are suitable
25 /// for most applications, unless multiple LEDs are being controlled.
26 GpioLed(int gpio_num, Mode mode = ON_LOW,
27 ledc_timer_t timer_num = LEDC_TIMER_0,
28 ledc_channel_t channel = LEDC_CHANNEL_0);
29
30 void setLevel(uint16_t level) override;
31 bool fade(uint16_t target_level, roo_time::Duration duration) override;
32
33 private:
34 int dutyForLevel(uint16_t level) const;
35
36 ledc_channel_t channel_;
37 Mode mode_;
38};
39
40/// Returns a GpioLed representing the built-in LED on the ESP32 board.
41Led& BuiltinLed();
42
43} // namespace esp32
44} // namespace roo_blink
45
46#endif