红外问题
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);
}
}
}
请问这是为什么啊 你没有让它停,它当然不停地发射天关机信号. 请问要如何写才能停止发射信息。。。。 //试一试这个
#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);
}
}
}
晚上回去试下,
但是代码中Serial.read() 这个是读取com口有没有数据的意思吧。 试了代码还是不行。。。。
只要执行过irsend.sendSony(0xa90, 12); 一次红外就亮,不灭。 抱歉
改一下
if (Serial.read() != -1 and stop==1)
改成
if (Serial.read() != -1 and stop<>1)
//试一试这个
#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);
}
}
}
发送不了红外,遥控电视无效。 //试一试这个
#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米都能遥控。 直接这样就可以了/*
* IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
* An IR LED must be connected to Arduino PWM pin 3.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
IRsend irsend;
int i;
void setup()
{
Serial.begin(57600);
}
void loop() {
if (Serial.read() != -1)
{
irsend.sendSony(0x810, 12); // Sony TV power code
delay(100);
}
}
你的程序我改了一下,也可以用#include <IRremote.h>
IRsend irsend;
int stop=0;//停止标志
int j=0;
void setup()
{
Serial.begin(57600);
}
void loop()
{
if (j>=10)
{
stop=1;
j=0;
}
if (Serial.read() != -1 && stop!=1)
{
j=j+1;
for (int i = 0; i < 3; i++)
{
Serial.println(111111);
irsend.sendSony(0x810, 12); // Sony TV power code
delay(100);
}
}
}
页:
[1]