I wanted to control a led from my Sony remote using an arduino with a TSOP1738 Ir sensor. I tried many codes but the only one that worked reliably for me was this one :
// --------------------------------------
// SIRCS (Sony IR Control System) Monitor
//
// Jon McPhalen
// www.jonmcphalen.com
// 30 NOV 2007
// --------------------------------------
int irPin = 7;
void setup()
{
pinMode(13, OUTPUT);
pinMode(irPin, INPUT);
Serial.begin(9600);
delay(25);
Serial.println("SIRCS Monitor\n");
}
void loop()
{
int key;
key = getSircs();
Serial.println(key, BIN);
delay(250);
}
int getSircs() {
int duration;
int irCode;
int mask;
// wait for start bit
do {
duration = pulseIn(irPin, LOW);
} while (duration < 2160 || duration > 2640);
// get 12-bit SIRCS code
irCode = 0; // clear ir code
mask = 1; // set mask to bit 0
for (int idx = 0; idx < 12; idx++) { // get all 12 bits
duration = pulseIn(irPin, LOW); // measure the bit pulse
if (duration >= 1080) // 1 bit?
irCode |= mask; // yes, update ir code
mask <<= 1; // shift mask to next bit
}
return irCode;
}
This code gave an output on the serial monitor depending one the button pressed.
I wanted it to toggle an LED on and off so i added the following code at the end, in between "return irCode;"
and "}"
}
{ if (key == 10010010) {
digitalWrite(13, HIGH);}
if (key == 10010011) {
digitalWrite(13, LOW);}
Problem is that my code doesn't compile- i get the following error-
"sketch_aug25a:50: error: expected unqualified-id before '{' token"
Could anyone help me out here?