极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9726|回复: 0

atemage8l的arduino最小系统串口输出问题

[复制链接]
发表于 2012-12-16 12:59:21 | 显示全部楼层 |阅读模式
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();
  }}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-1 12:13 , Processed in 0.038044 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表