极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13966|回复: 10

红外问题

[复制链接]
发表于 2012-11-17 21:15:34 | 显示全部楼层 |阅读模式
1.使用IRremote 库。
2.使用以下代码发现,红外一直亮,他不黑。
#include <IRremote.h>

IRsend irsend;

void setup()
{
  Serial.begin(9600);
}

void loop() {
  if (Serial.read() != -1) {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(100);
    }
  }
}


请问这是为什么啊
回复

使用道具 举报

发表于 2012-11-18 15:12:13 | 显示全部楼层
你没有让它停,它当然不停地发射天关机信号.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-18 15:26:00 | 显示全部楼层
请问要如何写才能停止发射信息。。。。
回复 支持 反对

使用道具 举报

发表于 2012-11-18 17:18:50 | 显示全部楼层
//试一试这个
#include <IRremote.h>

IRsend irsend;
int stop=0;//停止标志
int j=0;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  j=j+1;
  if (j==20)
   { stop=1;}
  if (Serial.read() != -1 and stop==1)
  {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(100);
    }
  }
}

回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-19 15:37:51 | 显示全部楼层
晚上回去试下,

但是代码中Serial.read() 这个是读取com口有没有数据的意思吧。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-19 20:52:48 | 显示全部楼层
试了代码还是不行。。。。

只要执行过irsend.sendSony(0xa90, 12); 一次红外就亮,不灭。
回复 支持 反对

使用道具 举报

发表于 2012-11-19 21:11:11 | 显示全部楼层
抱歉

改一下
if (Serial.read() != -1 and stop==1)

改成
if (Serial.read() != -1 and stop<>1)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-20 21:06:50 | 显示全部楼层

//试一试这个
#include <IRremote.h>

IRsend irsend;
int stop=0;//停止标志
int j=0;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  j=j+1;
  if (j==20)
   { stop=1;}
  if (Serial.read() != -1 and stop!=1)
  {
    for (int i = 0; i < 3; i++) {
      Serial.println(111111);
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(100);
    }
  }
}

发送不了红外,遥控电视无效。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-11-20 21:09:20 | 显示全部楼层
//试一试这个
#include <IRremote.h>

IRsend irsend;
int stop=0;//停止标志
int j=0;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  j=j+1;
  if (j==20)
   { stop=1;}
  delay(500);//加了这个能遥控电视了。但红外一直亮着
  if (Serial.read() != -1 and stop!=1)
  {
    for (int i = 0; i < 3; i++) {
      Serial.println(111111);
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(100);
    }
  }
}

我这个红外要放在电视面前,超过半米就遥控不了,电视遥控同个位置超过1米都能遥控。
回复 支持 反对

使用道具 举报

发表于 2012-12-1 14:54:39 | 显示全部楼层
直接这样就可以了
  1. /*
  2. * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
  3. * An IR LED must be connected to Arduino PWM pin 3.
  4. * Version 0.1 July, 2009
  5. * Copyright 2009 Ken Shirriff
  6. * http://arcfn.com
  7. */

  8. #include <IRremote.h>

  9. IRsend irsend;

  10. int i;
  11. void setup()
  12. {
  13.   Serial.begin(57600);
  14. }

  15. void loop() {
  16.   if (Serial.read() != -1)
  17.   {

  18.       irsend.sendSony(0x810, 12); // Sony TV power code
  19.       delay(100);
  20.   }

  21. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2012-12-1 14:58:53 | 显示全部楼层
你的程序我改了一下,也可以用
  1. #include <IRremote.h>

  2. IRsend irsend;
  3. int stop=0;//停止标志
  4. int j=0;
  5. void setup()
  6. {
  7.   Serial.begin(57600);
  8. }

  9. void loop()
  10. {
  11.   if (j>=10)
  12.   {
  13.     stop=1;
  14.     j=0;
  15.   }
  16.    
  17.   if (Serial.read() != -1 && stop!=1)
  18.   {
  19.       j=j+1;
  20.       
  21.     for (int i = 0; i < 3; i++)
  22.     {
  23.       Serial.println(111111);
  24.       irsend.sendSony(0x810, 12); // Sony TV power code
  25.       delay(100);
  26.     }
  27.   }
  28. }
复制代码
回复 支持 反对

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-5-5 00:33 , Processed in 0.039171 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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