编译环境: DELL 360 台式机
实验板:arduino Duemilanove 改进版控制板 ATmega8(看下面的连接)。
http://blog.ednchina.com/huanan_/1983286/message.aspx
http://item.taobao.com/auction/item_detail.htm?item_num_id=9342078118
编译环境:arduino 0022
编译器截图:
[attachimg]149187[/attachimg]
参考blog:
代码如下:
#define IRpin_PIN PIND
#define IRpin 2
#define MAXPULSE 65000
#define RESOLUTION 20
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing
void setup(void) {
Serial.begin(9600);
Serial.println("Ready to decode IR!");
}
void loop(void) {
uint16_t highpulse, lowpulse; // temporary storage timing
highpulse = lowpulse = 0; // start out with no pulse length
while (IRpin_PIN & (1 << IRpin)) {
highpulse++;
delayMicroseconds(RESOLUTION);
if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse=0;
return;
}
}
pulses[currentpulse][0] = highpulse;
while (! (IRpin_PIN & _BV(IRpin))) {
// pin is still LOW
lowpulse++;
delayMicroseconds(RESOLUTION);
if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse=0;
return;
}
}
pulses[currentpulse][1] = lowpulse;
currentpulse++;
}
void printpulses(void) {
Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
for (uint8_t i = 0; i < currentpulse; i++) {
Serial.print(pulses[0] * RESOLUTION, DEC);
Serial.print(" usec, ");
Serial.print(pulses[1] * RESOLUTION, DEC);
Serial.println(" usec");
}
Serial.println("int IRsignal[] = {");
Serial.println("// ON, OFF (in 10's of microseconds)");
for (uint8_t i = 0; i < currentpulse-1; i++) {
Serial.print("\t"); // tab
Serial.print(pulses[1] * RESOLUTION / 10, DEC);
Serial.print(", ");
Serial.print(pulses[i+1][0] * RESOLUTION / 10, DEC);
Serial.println(",");
}
Serial.print("\t"); // tab
Serial.print(pulses[currentpulse-1][1] * RESOLUTION / 10, DEC);
Serial.print(", 0};");
}
实验结果如下:
Ready to decode IR!
Received:
OFF ON
32488 usec, 40 usec
60 usec, 40 usec
60 usec, 20 usec
0 usec, 40 usec
80 usec, 20 usec
1940 usec, 20 usec
80 usec, 20 usec
80 usec, 20 usec
80 usec, 20 usec
int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
4, 6,
4, 6,
2, 0,
4, 8,
2, 194,
2, 8,
2, 8,
2, 8,
2, 0};
实验效果图:
[attachimg]149188[/attachimg]
[attachimg]149189[/attachimg]
文章评论(0条评论)
登录后参与讨论