Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[arduino code examples for KC868-AGv3]-03 IR send & receive
#1
Code:
/*
* SimpleReceiver.cpp
*
* Demonstrates receiving ONLY NEC protocol IR codes with IRremote
* If no protocol is defined, all protocols (except Bang&Olufsen) are active.
*
*  This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
*
************************************************************************************
* MIT License
*
* Copyright (c) 2020-2025 Armin Joachimsmeyer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
************************************************************************************
*/

#include <Arduino.h>
#include <IRremote.hpp> // include the library

uint8_t sender_pins[] = {47, 43,44};
uint8_t receiver_pin = 1;

int sender_pin_num = sizeof(sender_pins) / sizeof(sender_pins[0]);
uint8_t sender_pin_idx = 0;
uint8_t receive_cnt = 0;
uint8_t sCommand = 0x34;
uint8_t sRepeats = 0;

void setup() {
    Serial.begin(115200);
    IrReceiver.begin(receiver_pin, false);
    IrSender.begin(sender_pins[0]);

    xTaskCreate(
      sendIr,    // Function that should be called
      "Send IR",   // Name of the task (for debugging)
      4096,            // Stack size (bytes)
      NULL,            // Parameter to pass
      1,               // Task priority
      NULL             // Task handle
  );
}

void sendIr(void * parameter) {
 
  delay(1000);
  IrSender.setSendPin(47);
  IrSender.sendNEC(0x00, sCommand, sRepeats);
  Serial.printf("send by pin: %d\n", 47);
  delay(1000);

  IrSender.setSendPin(43);
  IrSender.sendNEC(0x00, sCommand, sRepeats);
  Serial.printf("send by pin: %d\n", 43);

  delay(1000);
  IrSender.setSendPin(44);
  IrSender.sendNEC(0x00, sCommand, sRepeats);
  Serial.printf("send by pin: %d\n", 44);
  delay(1000);

  vTaskDelete(NULL);
}

void loop() {
  if (IrReceiver.decode()) {
      Serial.println("recv data");
      if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
          Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
          // We have an unknown protocol here, print extended info
          IrReceiver.printIRResultRawFormatted(&Serial, true);

          IrReceiver.resume(); // Do it here, to preserve raw data for printing with printIRResultRawFormatted()
      } else {
          IrReceiver.resume(); // Early enable receiving of the next IR frame

          IrReceiver.printIRResultShort(&Serial);
          IrReceiver.printIRSendUsage(&Serial);
      }
  } else {
    // Serial.println("no data");
  }
}
arduino ino file download: 

.zip   SimpleSendReceiver.zip (Size: 1.63 KB / Downloads: 7)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   SimpleSendReceiver.ino.merged.zip (Size: 198.05 KB / Downloads: 5)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)