|
|
|
|
|
by bitbank
18 days ago
|
|
On the ESP32 I was able to successfully send codes using the PWM feature with the frequency set to 38KHz. Here's that code: //
// IR transmit
// Project started 10/12/2026
// written by Larry Bank
//
// Nano C6 IR LED on GPIO3
#define IR_LED 3
#define MARK 1
#define SPACE 0
//
// Send pulse
//
void SendPulse(int iCount, int iType) {
ledcWrite(IR_LED, (iType == MARK) ? 128 : 0); // 50% duty cycle when the signal is "on"
delayMicroseconds(562 * iCount); // continue this mark or space for N 562.5us periods
} /* SendPulse() /
//
// Transmit a 32-bit NEC IR code
//
void SendCode(uint32_t code) {
SendPulse(12, MARK); // start Mark
SendPulse(6, SPACE); // start space
// 562 on, 562 off = logical 0
// 562 on, 1687 off = logical 1
for (int iBit=0; iBit < 32; iBit++) {
SendPulse(1, MARK); // 562.5us mark
SendPulse((code & 0x80000000) ? 1 : 3, SPACE); // 562.5 or 1687.5us space for 1 or 0
code <<= 1;
}
SendPulse(1, MARK); // end of code
SendPulse(1, SPACE); // turn off the LED
} / SendCode() */ void setup() {
pinMode(IR_LED, OUTPUT);
ledcAttach(IR_LED, 38000, 8);
ledcWrite(IR_LED, 0); // start with it off while (1) {
SendCode(0xc03fe01f);
delay(1000);
}
}void loop() {
} |
|