const int GreenLED = 12;
const int RedLED = 13;
const int RECORD_BUTTON = 9;
const int PLAY_BUTTON = 8;
unsigned long last_input_push = 0;
unsigned long last_output_push = 0;
// Буфер для RAW-сигнала (макс. 100 пар = 200 элементов)
#define MAX_RAW_SIZE 200
uint16_t recordedSignal[MAX_RAW_SIZE];
uint16_t signal_length = 0;
// ir_recv
const int IRLED = 11;
#define IR_SEND_PIN 11
#include <IRremote.hpp>
const int IRReceiverPin = 10;
IRData savedIRData;
boolean NewCode = false;
boolean CodeState = false;
boolean Receiver_status = LOW;
boolean PLAY_BUTTON_state = HIGH;
void setup() {
Serial.begin(115200);
Serial.println("Запуск");
pinMode(RECORD_BUTTON, INPUT_PULLUP);
pinMode(PLAY_BUTTON, INPUT_PULLUP);
pinMode(GreenLED, OUTPUT);
pinMode(RedLED, OUTPUT);
IrReceiver.begin(IRReceiverPin, DISABLE_LED_FEEDBACK);
IrSender.begin(IRLED);
Serial.println("Все работает в норме");
}
void blink(int count, int pin){
for(int i = 0; i < count * 2; i++){
digitalWrite(pin, !digitalRead(pin));
delay(100);
}
}
void loop(){
NewCode = LOW;
if(digitalRead(RECORD_BUTTON) == LOW && millis() - last_input_push > 150){
digitalWrite(GreenLED, HIGH);
digitalWrite(RedLED, HIGH);
// Очистка буфера
IrReceiver.resume();
unsigned long start = millis();
while (millis() - start < 3000) {
if(IrReceiver.decode()){
NewCode = true;
auto myRawdata= IrReceiver.decodedIRData.decodedRawData;
//IrReceiver.printIRResultShort(&Serial);
IrReceiver.printIRResultRawFormatted(&Serial, true);
IrReceiver.printIRSendUsage(&Serial);
IrReceiver.resume();
break;
}
}
if(NewCode == HIGH){
blink(3, GreenLED);
}
else{
blink(3, RedLED);
}
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, LOW);
}
PLAY_BUTTON_state = digitalRead(PLAY_BUTTON);
if(PLAY_BUTTON_state == LOW && millis() - last_output_push > 500){
last_output_push = millis();
IrSender.sendSony(0x1, 0x15, 2, 12);
blink(2, GreenLED);
}
}
/*
IrReceiver.printIRResultShort(&Serial); // Кратко: протокол, адрес, команда
IrReceiver.printIRSendUsage(&Serial);
*/