求教:315MHz问题
#include <RCSwitch.h>RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
// Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2);
// Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15);
}
void loop() {
/* Same switch as above, but using decimal code */
mySwitch.send(13846320, 24);
delay(5000);
mySwitch.send(13846464, 24);
delay(5000);
}
采用Micro pro arduino + 315MHz收发模块
mySwitch.send(13846320, 24);
mySwitch.send(13846464, 24);
这两段代码中的“13846320”,“13846464”是用例程中的接收程序来获得的。
为何程序写到arduino 中后,执行过程中,通过315MHz发射模块发出信号后,所控制的灯一灭一亮地闪了一下,然后保持了原状态。这是什么问题呢?请教各位高人指点,谢谢!
把接收端的代码放出来看看 [木□易] 发表于 2014-8-28 15:27 static/image/common/back.gif
把接收端的代码放出来看看
/*
Simple example for receiving
http://code.google.com/p/rc-switch/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0);// Receiver on inerrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
}
mySwitch.resetAvailable();
}
}
接收端的代码 xiaoesky 发表于 2014-8-28 22:38 static/image/common/back.gif
/*
Simple example for receiving
/*
Example for receiving
http://code.google.com/p/rc-switch/
If you want to visualize a telegram copy the raw data and
paste it into http://test.sui.li/oszi/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0);// Receiver on inerrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}
使用这个程序,接收到的信号:
风扇开关
Decimal: 13846320 (24Bit) Binary: 110100110100011100110000 Tri-State: 1F01F0F10100 PulseLength: 266 microseconds Protocol: 1
Raw data: 8264,784,268,784,272,260,804,780,276,256,804,260,804,784,268,784,268,260,804,784,272,260,800,264,800,260,804,784,268,784,272,780,272,260,804,256,808,780,272,780,272,260,804,260,804,256,808,256,804,
如何发送这类的信号呢? 发送代码是不是改成这样子呢?
int fan_on={8264,784,268,784,272,260,804,780,276,256,804,260,804,784,268,784,268,260,804,784,272,260,800,264,800,260,804,784,268,784,272,780,272,260,804,256,808,780,272,780,272,260,804,260,804,256,808,256,804};
for(int i = 0;i<266;i++)
{
if(bWriteLow)digitalWrite(pin, LOW);
else digitalWrite(fan_pin, HIGH);
delayMicroseconds(fan_on);//这里延迟上面取到的微秒数,轮流一高一低一高一低
bWriteLow = !bWriteLow;
} 本帖最后由 xiaoesky 于 2014-8-29 14:11 编辑
如果将发送程序改成这样呢?
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
// Optional set pulse length.
mySwitch.setPulseLength(266);
// Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2);
// Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15);
}
void loop() {
/* Same switch as above, but using decimal code */
mySwitch.send(13846320, 24);
delay(5000);
mySwitch.send(13846464, 24);
delay(5000);
}
你这个接收端我咋没看到控制灯的代码呢
页:
[1]