|
atemage8l的arduino最小系统 ,采用中断方式识别红外信号,并通过串口输出。当没有红色部分时,程序输出正常,当把红色加上后,只能输出"Heard "然后不管么样按遥控都无反应。代码如下:
#define IRpin_PIN PIND
#define IRpin 2
#define MAXPULSE 65000
#define RESOLUTION 20
#define FUZZINESS 20
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing
//Received: 左
int IRsignalL[] = {
// ON, OFF (in 10's of microseconds)
868, 424,
58, 48,
58, 48,
54, 52,
54, 52,
56, 50,
56, 50,
54, 162,
54, 52,
54, 50,
56, 50,
54, 164,
54, 162,
54, 52,
54, 162,
54, 54,
54, 52,
54, 50,
56, 162,
54, 162,
56, 162,
52, 52,
54, 52,
54, 50,
56, 54,
52, 160,
58, 50,
56, 50,
54, 52,
52, 164,
54, 162,
54, 164,
54, 162,
54, 3800,
864, 212,
56, 0};
//Received: 右
int IRsignalR[] = {
// ON, OFF (in 10's of microseconds)
868, 420,
58, 50,
54, 50,
56, 54,
54, 50,
56, 48,
56, 52,
54, 162,
54, 50,
56, 50,
54, 54,
54, 162,
56, 162,
54, 50,
56, 162,
54, 52,
52, 52,
54, 52,
54, 162,
54, 52,
54, 164,
56, 162,
52, 52,
54, 52,
54, 50,
56, 162,
54, 50,
54, 162,
56, 50,
54, 52,
56, 162,
54, 162,
54, 164,
52, 3804,
862, 210,
58, 6035,
8, 0};
void setup(void) {
Serial.begin(9600);
Serial.println("Ready to decode IR!");
}
void loop(void) {
int numpulses;
numpulses = listenForIR();
Serial.print("Heard ");
Serial.print(numpulses);
Serial.println("-pulse long IR signal");
/*
IRcompare(numberpulses, IRsignalL);
IRcompare(numberpulses, IRsignalR);
IRcompare(numberpulses, IRsignalU);
IRcompare(numberpulses, IRsignalD);*/
//###################################################
for (int i=0; i< numpulses-1; i++) {
int oncode = pulses[1] * RESOLUTION / 10;
int offcode = pulses[i+1][0] * RESOLUTION / 10;
Serial.print(oncode); // the ON signal we heard
Serial.print(" - ");
Serial.print(IRsignalL[i*2 + 0]); // the ON signal we want
// check to make sure the error is less than FUZZINESS percent
if ( abs(oncode - IRsignalL[i*2 + 0]) <= (oncode * FUZZINESS / 100)) {
// Serial.print(" (ok)");
} else {
Serial.print(" (x)");
}
Serial.print(" \t"); // tab
Serial.print(offcode); // the OFF signal we heard
Serial.print(" - ");
Serial.print(IRsignalL[i*2 + 1]); // the OFF signal we want
if ( abs(offcode - IRsignalL[i*2 + 1]) <= (offcode * FUZZINESS / 100)) {
// Serial.print(" (ok)");
} else {
Serial.print(" (x)");
}
Serial.println();
}
// ApplePlaySignal=IRsignalR;
for (int i1=0; i1< numpulses-1; i1++) {
int oncode1 = pulses[i1][1] * RESOLUTION / 10;
int offcode1 = pulses[i1+1][0] * RESOLUTION / 10;
Serial.print(oncode1); // the ON signal we heard
Serial.print(" - ");
Serial.print(IRsignalR[i1*2 + 0]); // the ON signal we want
// check to make sure the error is less than FUZZINESS percent
if ( abs(oncode1 - IRsignalR[i1*2 + 0]) <= (oncode1 * FUZZINESS / 100)) {
// Serial.print(" (ok)");
} else {
Serial.print(" (x)");
}
Serial.print(" \t"); // tab
Serial.print(offcode1); // the OFF signal we heard
Serial.print(" - ");
Serial.print(IRsignalR[i1*2 + 1]); // the OFF signal we want
if ( abs(offcode1 - IRsignalR[i1*2 + 1]) <= (offcode1 * FUZZINESS / 100)) {
// Serial.print(" (ok)");
} else {
Serial.print(" (x)");
}
Serial.println(); }} |
|