I have the following script which checks if the user has pressed the numbers "770" or "769" continuously in the remote. The script works fine and displays all numbers. When I press the buttons "770" or "769" continuously the function powerOff() is called and I get no serial input.
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
int intValue;
String strValue;
String str3;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
intValue = results.value;
Serial.print("Integer value : ");
Serial.println(intValue);
strValue = String(intValue);
Serial.print("String str : ");
Serial.println(strValue);
Serial.print("Length : ");
Serial.print(strValue.length());
Serial.println();
if(strValue.length() <= 1){
str3 += strValue;
Serial.println(str3);
// Receive the next value
}
delay(200);
irrecv.resume();
}
//Serial.println(str3);
if(str3.endsWith("770")){
powerOff();
str3 = "";
}
else if(str3.endsWith("769")){
powerOff();
str3 = "";
}
else{}
//powerOff();
}
void powerOff(){
irsend.sendRC6( 0xC0000C, 24);
irrecv.resume(); // Receive the next value
}
1 Answer 1
Apparently you should be calling irrecv.enableIRIn()
after sending, not irrecv.resume()
. Sorry for suggesting the wrong thing on IRC before :-)
Explore related questions
See similar questions with these tags.