Dezibot 4
Loading...
Searching...
No Matches
InfraredLED.cpp
Go to the documentation of this file.
1#include "InfraredLight.h"
2
3#define pwmSpeedMode LEDC_LOW_SPEED_MODE
4
5InfraredLED::InfraredLED(uint8_t pin,ledc_timer_t timer, ledc_channel_t channel){
6 this->ledPin = pin;
7 this->timer = timer;
8 this->channel = channel;
9};
10
12 //we want to change frequency instead of
13 pwmTimer = ledc_timer_config_t{
14 .speed_mode = pwmSpeedMode,
15 .duty_resolution = LEDC_TIMER_10_BIT,
16 .timer_num = this->timer,
17 .freq_hz = 800,
18 .clk_cfg = LEDC_AUTO_CLK
19 };
20 ledc_timer_config(&pwmTimer);
21
22 pwmChannel = ledc_channel_config_t{
23 .gpio_num = this->ledPin,
24 .speed_mode =pwmSpeedMode,
25 .channel = this->channel,
26 .intr_type = LEDC_INTR_DISABLE,
27 .timer_sel = this->timer,
28 .duty = 0,
29 .hpoint = 0
30 };
31 ledc_channel_config(&pwmChannel);
32};
33
36};
37
40};
41
42void InfraredLED::setState(bool state){
43 ledc_set_freq(pwmSpeedMode,timer,1);
44 if (state) {
45 ledc_set_duty(pwmSpeedMode,channel,1023);
46 } else {
47 ledc_set_duty(pwmSpeedMode,channel,0);
48 }
49 ledc_update_duty(pwmSpeedMode,channel);
50
51};
52
53void InfraredLED::sendFrequency(uint16_t frequency){
54 ledc_set_freq(pwmSpeedMode,timer,frequency);
55 ledc_set_duty(pwmSpeedMode,channel,512);
56 ledc_update_duty(pwmSpeedMode,channel);
57};
#define pwmSpeedMode
Adds the ability to print to the display of the robot.
void begin(void)
InfraredLED(uint8_t pin, ledc_timer_t timer, ledc_channel_t channel)
ledc_timer_t timer
void turnOn(void)
enables selected LED
ledc_channel_config_t pwmChannel
void turnOff(void)
disables selected LED
void sendFrequency(uint16_t frequency)
starts flashing the IRLed with a specific frequency Won't stop automatically, must be stopped by call...
ledc_channel_t channel
uint8_t ledPin
ledc_timer_config_t pwmTimer
void setState(bool state)
changes state of selected LED depending on the state