Merge pull request #157 from nuclearcat/add-inverted-led
Add inverted LED support to IRSenderESP32
This commit is contained in:
commit
c8369594f4
|
@ -44,6 +44,14 @@ uint8_t IRSender::bitReverse(uint8_t x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Some boards have inverted signals, so we need to set the pin to HIGH to turn the IR transmitter off
|
||||||
|
// For example M5Stick-C where LED positive on VCC and negative on pin 9
|
||||||
|
void IRSender::invert(bool inverted)
|
||||||
|
{
|
||||||
|
_inverted = inverted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Definitions of virtual functions
|
// Definitions of virtual functions
|
||||||
void IRSender::setFrequency(int) {};
|
void IRSender::setFrequency(int) {};
|
||||||
void IRSender::space(int) {};
|
void IRSender::space(int) {};
|
||||||
|
|
|
@ -29,11 +29,13 @@ class IRSender
|
||||||
virtual void setFrequency(int frequency);
|
virtual void setFrequency(int frequency);
|
||||||
void sendIRbyte(uint8_t sendByte, int bitMarkLength, int zeroSpaceLength, int oneSpaceLength);
|
void sendIRbyte(uint8_t sendByte, int bitMarkLength, int zeroSpaceLength, int oneSpaceLength);
|
||||||
uint8_t bitReverse(uint8_t x);
|
uint8_t bitReverse(uint8_t x);
|
||||||
|
virtual void invert(bool inverted);
|
||||||
virtual void space(int spaceLength);
|
virtual void space(int spaceLength);
|
||||||
virtual void mark(int markLength);
|
virtual void mark(int markLength);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t _pin;
|
uint8_t _pin;
|
||||||
|
bool _inverted = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,10 @@ IRSenderESP32::IRSenderESP32(uint8_t pin, uint8_t pwmChannel) : IRSender(pin)
|
||||||
{
|
{
|
||||||
_pwmChannel = pwmChannel;
|
_pwmChannel = pwmChannel;
|
||||||
pinMode(_pin, OUTPUT);
|
pinMode(_pin, OUTPUT);
|
||||||
|
// If we have an inverted signal, we need to set the pin from default LOW
|
||||||
|
// to HIGH to make it off
|
||||||
|
if (_inverted)
|
||||||
|
digitalWrite(_pin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRSenderESP32::setFrequency(int frequency)
|
void IRSenderESP32::setFrequency(int frequency)
|
||||||
|
@ -37,13 +41,19 @@ void IRSenderESP32::mark(int markLength)
|
||||||
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
|
#endif // ESP_ARDUINO_VERSION_MAJOR >= 3
|
||||||
while((int)(micros() - beginning) < markLength);
|
while((int)(micros() - beginning) < markLength);
|
||||||
gpio_reset_pin(static_cast<gpio_num_t>(_pin));
|
gpio_reset_pin(static_cast<gpio_num_t>(_pin));
|
||||||
digitalWrite(_pin, LOW);
|
if (_inverted)
|
||||||
|
digitalWrite(_pin, HIGH);
|
||||||
|
else
|
||||||
|
digitalWrite(_pin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send an IR 'space' symbol, i.e. transmitter OFF
|
// Send an IR 'space' symbol, i.e. transmitter OFF
|
||||||
void IRSenderESP32::space(int spaceLength)
|
void IRSenderESP32::space(int spaceLength)
|
||||||
{
|
{
|
||||||
digitalWrite(_pin, LOW);
|
if (_inverted)
|
||||||
|
digitalWrite(_pin, HIGH);
|
||||||
|
else
|
||||||
|
digitalWrite(_pin, LOW);
|
||||||
|
|
||||||
if (spaceLength < 16383) {
|
if (spaceLength < 16383) {
|
||||||
delayMicroseconds(spaceLength);
|
delayMicroseconds(spaceLength);
|
||||||
|
|
Loading…
Reference in New Issue