ИК передатчик и приемник

FlatronBuda
Offline
Зарегистрирован: 24.11.2015

Сделал приемник передатчик
Контакты
8- приемник кода
9- обычная лампочка для теста
3- отправляет команды при выполнеии

1 и 2 условия всего работает хорошо лампочка на пине 9 вкл и выкл.
Проблема
При наступлении 3 условия ардуино тупо зависает

#include <IRremote.h>
#include <IRremoteInt.h>

int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;


IRsend irsend;
void setup()
{

  pinMode(9, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); 
}

void loop() {
  if (irrecv.decode(&results)) {
    //Serial.println(results.value, HEX);
    int res = results.value;
   Serial.println(res, HEX);
    if (res == 0xFFFFA857) // Если нажата кнопка "+"
    {
      digitalWrite(9, HIGH);   // set the LED on
    }
    else if (res == 0xFFFFE01F) // Если нажата кнопка "-"
    {
      digitalWrite(9, LOW);    // set the LED off
      digitalWrite(2, LOW);   // set the LED on
    }
    else if (res == 0xFFFFC23D) // Если нажата кнопка "0"
    {
      digitalWrite(9, HIGH);   // set the LED on
      Serial.println("Run");
      //digitalWrite(2, HIGH);   // set the LED on
          delay(40);
      for (int i = 0; i < 3; i++) {
irsend.sendNEC(0x20DF55AA,32);
        delay(40);
      }
      Serial.println("Stop");
      exit(0);

    }

    irrecv.resume(); // Receive the next value
    delay(100);
  }
}

 

FlatronBuda
Offline
Зарегистрирован: 24.11.2015

исправил свой код тема закрыта

вот сам код

#include <IRremote.h>
#include <IRremoteInt.h>

int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

IRsend irsend;
void setup()
{
  pinMode(9, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {

  if (irrecv.decode(&results)) {
    int res = results.value;
   Serial.println(res, HEX);
    if (res == 0xFFFFA857) // Если нажата кнопка "+"
    {
      digitalWrite(9, HIGH);   // set the LED on
    }
    else if (res == 0xFFFFE01F) // Если нажата кнопка "-"
    {
      digitalWrite(9, LOW);    // set the LED off
    }
    else if (res == 0xFFFFC23D) // Если нажата кнопка "0"
    {
      digitalWrite(9, HIGH);   // set the LED on
          delay(40);
      for (int i = 0; i < 3; i++) {
irsend.sendNEC(0x20DF55AA,32);
        delay(40);
      }
      irrecv.enableIRIn();
    //irrecv.resume(); // Receive the next value
      Serial.println("Stop");

    }
    irrecv.resume(); // Receive the next value
    delay(100);
  }
}

 

kisoft
kisoft аватар
Offline
Зарегистрирован: 13.11.2012

Резюме для тех, кто не хочется копаться в коде: после любой отправки кода необходимо разрешить прием.

irrecv.enableIRIn();