pleasedontcode

IR Transmitter rev_02

Sep 24th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: IR Transmitter
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-09-24 19:45:42
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Напиши скетч который будет перебирать и отправлять */
  21.     /* на IR transmitter сигналы включения большинства */
  22.     /* марок телевизоров (желательно чтобы любой */
  23.     /* телевизор при наведении на него устройства */
  24.     /* включился/отключился). потом расскажи как */
  25.     /* подключить трансмиттер */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28.  
  29. /* START CODE */
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <IRsend.h>
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void testAllTVbrands();
  38. void sendBrandPower(int index);
  39.  
  40. enum Protocol { NEC_PROTOCOL, SONY_PROTOCOL, SAMSUNG_PROTOCOL, LG_PROTOCOL };
  41.  
  42. struct TVCode {
  43.   const char* brand;
  44.   Protocol protocol;
  45.   uint32_t data;
  46.   uint16_t nbits;
  47. };
  48.  
  49. // List of known TV brands and their power codes (best effort for common models)
  50. static const TVCode tvCodes[] = {
  51.   {"Samsung", SAMSUNG_PROTOCOL, 0xE0E040BF, 32},
  52.   {"LG", NEC_PROTOCOL, 0x20DF10EF, 32},
  53.   {"Sony", SONY_PROTOCOL, 0xA90, 12}
  54. };
  55.  
  56. static const size_t numBrands = sizeof(tvCodes)/sizeof(tvCodes[0]);
  57.  
  58. const int IR_LED_PIN = 4; // GPIO connected to IR LED
  59. IRsend irsend(IR_LED_PIN);
  60.  
  61. unsigned long lastTestMillis = 0;
  62. const unsigned long TEST_INTERVAL = 15000; // 15 seconds between test cycles
  63.  
  64. void setup(void)
  65. {
  66.     // put your setup code here, to run once:
  67.     Serial.begin(115200);
  68.     while(!Serial) ;
  69.     irsend.begin();
  70.     Serial.println("IR TX transmitter ready");
  71. }
  72.  
  73.  
  74. void loop(void)
  75. {
  76.     unsigned long now = millis();
  77.     if (now - lastTestMillis >= TEST_INTERVAL) {
  78.         testAllTVbrands();
  79.         lastTestMillis = now;
  80.     }
  81. }
  82.  
  83. void testAllTVbrands()
  84. {
  85.     Serial.println("Sending power codes for known brands...");
  86.     for (size_t i=0; i<numBrands; ++i) {
  87.         Serial.print("Brand: "); Serial.println(tvCodes[i].brand);
  88.         sendBrandPower(i);
  89.         delay(120); // slight pause between transmissions
  90.     }
  91.     Serial.println("Done sending codes.");
  92. }
  93.  
  94. void sendBrandPower(int index)
  95. {
  96.     if (index < 0 || index >= (int)numBrands) return;
  97.     const TVCode& c = tvCodes[index];
  98.     Serial.print("Sending "); Serial.print(c.brand);
  99.     Serial.print(" power code using ");
  100.     switch (c.protocol) {
  101.         case NEC_PROTOCOL: Serial.println("NEC"); break;
  102.         case SONY_PROTOCOL: Serial.println("Sony"); break;
  103.         case SAMSUNG_PROTOCOL: Serial.println("Samsung"); break;
  104.         case LG_PROTOCOL: Serial.println("LG"); break;
  105.         default: Serial.println("Unknown"); break;
  106.     }
  107.     switch (c.protocol) {
  108.         case NEC_PROTOCOL: irsend.sendNEC(c.data, c.nbits); break;
  109.         case SONY_PROTOCOL: irsend.sendSony(c.data, c.nbits); break;
  110.         case SAMSUNG_PROTOCOL: irsend.sendSAMSUNG(c.data, c.nbits); break;
  111.         case LG_PROTOCOL: irsend.sendLG(c.data, c.nbits); break;
  112.     }
  113.     delay(60);
  114. }
  115.  
  116. /* END CODE */
  117.  
Advertisement
Add Comment
Please, Sign In to add comment