forked from ToniA/arduino-heatpumpir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRSenderESP32.cpp
44 lines (37 loc) · 1001 Bytes
/
IRSenderESP32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <Arduino.h>
// IRSender implementation for ESP32
// Tested on R51M/E control with SENSEI air conditioner
// Maksym Krasovskyi
#if defined ESP32
#include <IRSender.h>
IRSenderESP32::IRSenderESP32(uint8_t pin, uint8_t pwmChannel) : IRSender(pin)
{
_pwmChannel = pwmChannel;
pinMode(_pin, OUTPUT);
}
void IRSenderESP32::setFrequency(int frequency)
{
_frequency = frequency * 1000;
}
// Send an IR 'mark' symbol, i.e. transmitter ON
void IRSenderESP32::mark(int markLength)
{
ledcSetup(_pwmChannel, _frequency, 8);
ledcAttachPin(_pin, _pwmChannel);
long beginning = micros();
ledcWrite(_pwmChannel, 127);
while((int)(micros() - beginning) < markLength);
gpio_reset_pin(static_cast<gpio_num_t>(_pin));
digitalWrite(_pin, LOW);
}
// Send an IR 'space' symbol, i.e. transmitter OFF
void IRSenderESP32::space(int spaceLength)
{
digitalWrite(_pin, LOW);
if (spaceLength < 16383) {
delayMicroseconds(spaceLength);
} else {
delay(spaceLength/1000);
}
}
#endif