极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11833|回复: 6

求教:315MHz问题

[复制链接]
发表于 2014-8-28 01:23:18 | 显示全部楼层 |阅读模式
[pre lang="arduino" line="1" file="send_315"]#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);  
}[/code]

采用Micro pro arduino + 315MHz收发模块

  mySwitch.send(13846320, 24);
  mySwitch.send(13846464, 24);  
这两段代码中的“13846320”,“13846464”是用例程中的接收程序来获得的。
为何程序写到arduino 中后,执行过程中,通过315MHz发射模块发出信号后,所控制的灯一灭一亮地闪了一下,然后保持了原状态。这是什么问题呢?请教各位高人指点,谢谢!
回复

使用道具 举报

发表于 2014-8-28 15:27:44 | 显示全部楼层
把接收端的代码放出来看看
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-8-28 22:38:52 | 显示全部楼层
[木□易] 发表于 2014-8-28 15:27
把接收端的代码放出来看看
  1. /*
  2.   Simple example for receiving
  3.   
  4.   [url]http://code.google.com/p/rc-switch/[/url]
  5. */

  6. #include <RCSwitch.h>

  7. RCSwitch mySwitch = RCSwitch();

  8. void setup() {
  9.   Serial.begin(9600);
  10.   mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  11. }

  12. void loop() {
  13.   if (mySwitch.available()) {
  14.    
  15.     int value = mySwitch.getReceivedValue();
  16.    
  17.     if (value == 0) {
  18.       Serial.print("Unknown encoding");
  19.     } else {
  20.       Serial.print("Received ");
  21.       Serial.print( mySwitch.getReceivedValue() );
  22.       Serial.print(" / ");
  23.       Serial.print( mySwitch.getReceivedBitlength() );
  24.       Serial.print("bit ");
  25.       Serial.print("Protocol: ");
  26.       Serial.println( mySwitch.getReceivedProtocol() );
  27.     }

  28.     mySwitch.resetAvailable();
  29.   }
  30. }
复制代码


接收端的代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-8-29 00:20:02 | 显示全部楼层
xiaoesky 发表于 2014-8-28 22:38
/*
  Simple example for receiving
  

[pre lang="arduino" line="1" file="ReceiveDemo_Advanced"]/*
  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();
  }
}[/code]

使用这个程序,接收到的信号:

风扇开关

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,

如何发送这类的信号呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-8-29 12:57:52 | 显示全部楼层
发送代码是不是改成这样子呢?

  1. int fan_on[266]={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};
  2. for(int i = 0;i<266;i++)
  3.   {
  4.     if(bWriteLow)digitalWrite(pin, LOW);
  5.     else digitalWrite(fan_pin, HIGH);
  6.     delayMicroseconds(fan_on[i]);//这里延迟上面取到的微秒数,轮流一高一低一高一低
  7.     bWriteLow = !bWriteLow;
  8.   }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-8-29 14:10:15 | 显示全部楼层
本帖最后由 xiaoesky 于 2014-8-29 14:11 编辑

如果将发送程序改成这样呢?

  1. #include <RCSwitch.h>

  2. RCSwitch mySwitch = RCSwitch();

  3. void setup() {

  4.   Serial.begin(9600);

  5.   // Transmitter is connected to Arduino Pin #10  
  6.   mySwitch.enableTransmit(10);

  7.   // Optional set pulse length.
  8. mySwitch.setPulseLength(266);

  9.   // Optional set protocol (default is 1, will work for most outlets)
  10.   // mySwitch.setProtocol(2);

  11.   // Optional set number of transmission repetitions.
  12.   // mySwitch.setRepeatTransmit(15);

  13. }

  14. void loop() {

  15.   /* Same switch as above, but using decimal code */
  16.   mySwitch.send(13846320, 24);
  17.   delay(5000);  
  18.   mySwitch.send(13846464, 24);  
  19.   delay(5000);  
  20. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2014-9-3 17:39:22 | 显示全部楼层
你这个接收端我咋没看到控制灯的代码呢
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 23:38 , Processed in 0.052357 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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