Dezibot 4
InfraredLED.cpp
Go to the documentation of this file.
1
#include "
InfraredLight.h
"
2
3
#define pwmSpeedMode LEDC_LOW_SPEED_MODE
4
5
InfraredLED::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
11
void
InfraredLED::begin
(
void
){
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
34
void
InfraredLED::turnOn
(
void
){
35
InfraredLED::setState
(
true
);
36
};
37
38
void
InfraredLED::turnOff
(
void
){
39
InfraredLED::setState
(
false
);
40
};
41
42
void
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
53
void
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
};
InfraredLED::InfraredLED
InfraredLED(uint8_t pin, ledc_timer_t timer, ledc_channel_t channel)
Definition:
InfraredLED.cpp:5
InfraredLED::turnOn
void turnOn(void)
enables selected LED
Definition:
InfraredLED.cpp:34
pwmSpeedMode
#define pwmSpeedMode
Definition:
InfraredLED.cpp:3
InfraredLED::ledPin
uint8_t ledPin
Definition:
InfraredLight.h:48
InfraredLED::pwmChannel
ledc_channel_config_t pwmChannel
Definition:
InfraredLight.h:52
InfraredLED::sendFrequency
void sendFrequency(uint16_t frequency)
starts flashing the IRLed with a specific frequency Won't stop automatically, must be stopped by call...
Definition:
InfraredLED.cpp:53
InfraredLED::timer
ledc_timer_t timer
Definition:
InfraredLight.h:49
InfraredLED::pwmTimer
ledc_timer_config_t pwmTimer
Definition:
InfraredLight.h:51
InfraredLED::turnOff
void turnOff(void)
disables selected LED
Definition:
InfraredLED.cpp:38
InfraredLED::setState
void setState(bool state)
changes state of selected LED depending on the state
Definition:
InfraredLED.cpp:42
InfraredLED::channel
ledc_channel_t channel
Definition:
InfraredLight.h:50
InfraredLight.h
Adds the ability to print to the display of the robot.
InfraredLED::begin
void begin(void)
Definition:
InfraredLED.cpp:11
src
infraredLight
InfraredLED.cpp
Generated by
1.8.17