Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: IR Transmitter
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-09-24 19:45:42
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Напиши скетч который будет перебирать и отправлять */
- /* на IR transmitter сигналы включения большинства */
- /* марок телевизоров (желательно чтобы любой */
- /* телевизор при наведении на него устройства */
- /* включился/отключился). потом расскажи как */
- /* подключить трансмиттер */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <IRsend.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void testAllTVbrands();
- void sendBrandPower(int index);
- enum Protocol { NEC_PROTOCOL, SONY_PROTOCOL, SAMSUNG_PROTOCOL, LG_PROTOCOL };
- struct TVCode {
- const char* brand;
- Protocol protocol;
- uint32_t data;
- uint16_t nbits;
- };
- // List of known TV brands and their power codes (best effort for common models)
- static const TVCode tvCodes[] = {
- {"Samsung", SAMSUNG_PROTOCOL, 0xE0E040BF, 32},
- {"LG", NEC_PROTOCOL, 0x20DF10EF, 32},
- {"Sony", SONY_PROTOCOL, 0xA90, 12}
- };
- static const size_t numBrands = sizeof(tvCodes)/sizeof(tvCodes[0]);
- const int IR_LED_PIN = 4; // GPIO connected to IR LED
- IRsend irsend(IR_LED_PIN);
- unsigned long lastTestMillis = 0;
- const unsigned long TEST_INTERVAL = 15000; // 15 seconds between test cycles
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(115200);
- while(!Serial) ;
- irsend.begin();
- Serial.println("IR TX transmitter ready");
- }
- void loop(void)
- {
- unsigned long now = millis();
- if (now - lastTestMillis >= TEST_INTERVAL) {
- testAllTVbrands();
- lastTestMillis = now;
- }
- }
- void testAllTVbrands()
- {
- Serial.println("Sending power codes for known brands...");
- for (size_t i=0; i<numBrands; ++i) {
- Serial.print("Brand: "); Serial.println(tvCodes[i].brand);
- sendBrandPower(i);
- delay(120); // slight pause between transmissions
- }
- Serial.println("Done sending codes.");
- }
- void sendBrandPower(int index)
- {
- if (index < 0 || index >= (int)numBrands) return;
- const TVCode& c = tvCodes[index];
- Serial.print("Sending "); Serial.print(c.brand);
- Serial.print(" power code using ");
- switch (c.protocol) {
- case NEC_PROTOCOL: Serial.println("NEC"); break;
- case SONY_PROTOCOL: Serial.println("Sony"); break;
- case SAMSUNG_PROTOCOL: Serial.println("Samsung"); break;
- case LG_PROTOCOL: Serial.println("LG"); break;
- default: Serial.println("Unknown"); break;
- }
- switch (c.protocol) {
- case NEC_PROTOCOL: irsend.sendNEC(c.data, c.nbits); break;
- case SONY_PROTOCOL: irsend.sendSony(c.data, c.nbits); break;
- case SAMSUNG_PROTOCOL: irsend.sendSAMSUNG(c.data, c.nbits); break;
- case LG_PROTOCOL: irsend.sendLG(c.data, c.nbits); break;
- }
- delay(60);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment