#include #include // AtomS3 / AtomS3 Lite onboard IR LED, per M5Stack's own ir_nec example. #define IR_TX_PIN 4 #define NEC_ADDRESS 0xDF00 struct ButtonCode { const char* name; uint8_t command; }; // Decoded from the ComXim remote (address 0xDF00) via the WROOM IR tap. const ButtonCode BUTTONS[] = { {"step", 0x40}, // Repeated Step Mode {"ccw", 0x41}, // Counterclockwise {"startstop", 0x42}, // Start/Stop {"slowdown", 0x43}, // Slow Down (-) {"cw", 0x44}, // Clockwise {"continuous", 0x45}, // Continuous Rotation Mode {"45", 0x02}, // 45 degrees {"180", 0x07}, // 180 degrees {"speedup", 0x0A}, // Speed Up (+) {"swing", 0x11}, // Pendulum (Swing) Mode {"90", 0x1B}, // 90 degrees }; const int NUM_BUTTONS = sizeof(BUTTONS) / sizeof(BUTTONS[0]); void setup() { Serial.begin(115200); while (!Serial) { ; } IrSender.begin(IR_TX_PIN); Serial.println(); Serial.println("=============================================="); Serial.println("PROJECT SLOW-SWEEP: IR TRANSMITTER (ATOM S3 Lite)"); Serial.println("=============================================="); Serial.print("Known buttons: "); for (int i = 0; i < NUM_BUTTONS; i++) { Serial.print(BUTTONS[i].name); if (i < NUM_BUTTONS - 1) Serial.print(", "); } Serial.println(); Serial.println("Type a button name (or 0xNN hex command) and press Enter."); } void loop() { if (Serial.available()) { String cmd = Serial.readStringUntil('\n'); cmd.trim(); cmd.toLowerCase(); if (cmd.length() == 0) return; int command = -1; for (int i = 0; i < NUM_BUTTONS; i++) { if (cmd.equals(BUTTONS[i].name)) { command = BUTTONS[i].command; break; } } if (command < 0) { command = (int)strtol(cmd.c_str(), nullptr, 16); } if (command < 0 || command > 0xFF) { Serial.printf("[ERROR] unrecognized button/command: %s\n", cmd.c_str()); return; } Serial.printf("[SEND] %s -> address=0x%04X command=0x%02X\n", cmd.c_str(), NEC_ADDRESS, command); IrSender.sendNEC(NEC_ADDRESS, (uint8_t)command, 2); } }