ESPMegaPRO-v3-SDK/ESPMegaPRO-firmware/lib/ESPMegaPRO/Untitled-1.cpp

33 lines
1.0 KiB
C++

#include "driver/rmt.h"
#define RMT_TX_CHANNEL RMT_CHANNEL_0
#define RMT_TX_GPIO_NUM GPIO_NUM_4
void app_main() {
// Configure RMT transmitter
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(RMT_TX_GPIO_NUM, RMT_TX_CHANNEL);
config.clk_div = 80; // Set clock divider for desired frequency (80MHz / 80 = 1MHz)
rmt_config(&config);
rmt_driver_install(config.channel, 0, 0);
// Define NEC IR protocol parameters
uint16_t irTimingArray[] = { /* Your IR timing array here */ };
size_t itemCount = sizeof(irTimingArray) / sizeof(irTimingArray[0]);
rmt_item32_t items[itemCount];
// Convert IR timing array to RMT items
for (size_t i = 0; i < itemCount; i++) {
items[i].level0 = 1;
items[i].duration0 = irTimingArray[i];
items[i].level1 = 0;
items[i].duration1 = irTimingArray[i];
}
// Send IR signal
rmt_write_items(config.channel, items, itemCount, true);
rmt_wait_tx_done(config.channel, portMAX_DELAY);
// Cleanup RMT driver
rmt_driver_uninstall(config.channel);
}