Arduino 433 + 串口
http://www.freebuf.com/articles/wireless/105398.html

/*本作品使用的例程中包含RCSwitch库文件用于信号的解码和编码发送*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
//串口打印命令帮助信息
Serial.print("HELP:A-flash the lamp A\n B-flash the lamp B\n C-flash the lamp C\n D-flash the lamp D\n");
Serial.print(" a-open the lamp A\n b-open the lamp B\n c-open the lamp C\n d-open the lamp D\n\n");
mySwitch.enableReceive(1);
mySwitch.enableTransmit(10);}2
void loop()
{
if(mySwitch.available())
{
output(mySwitch.getReceivedValue(),mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(),mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
/* Same switch as above,but using binary code */
if(Serial.available()>0)//如果串口有数据进入的话
{ delay(10); //延时50 可以一次性发送多个命令
char M=Serial.read();//每次读一个字符,是ASCII码的
if(M=='A')
{
Serial.print("Thecommand is A\n");
mySwitch.send("010101010101010100001100");//遥控器-A
Serial.print(" OK!!! The LED A has been DONE\n");
}
if(M=='a')
{
Serial.print("The command is a\n");
Serial.print(" OK!!! TheLED A has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010100001100");//遥控器-A 按下不放
}
}
if(M=='B')
{
Serial.print("Thecommand is B\n");
mySwitch.send("010101010101010111000000");//遥控器-B
Serial.print(" OK!!! The LED B has been DONE\n");
}
if(M=='b')
{
Serial.print("The command is b\n");
Serial.print(" OK!!! The LED B has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010111000000");//遥控器-B 按下不放
}
}
if(M=='C')
{
Serial.print("Thecommand is C\n");
mySwitch.send("010101010101010100000011");//遥控器-C
Serial.print(" OK!!! The LED C has been DONE\n");
}
if(M=='c')
{
Serial.print("The command is c\n");
Serial.print(" OK!!! TheLED C has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010100000011");//遥控器-C按下不放
}
}
if(M=='D')
{
Serial.print("Thecommand is D\n");
mySwitch.send("010101010101010100110000");//遥控器-D
Serial.print(" OK!!! The LED D has been DONE\n");
}
if(M=='d')
{
Serial.print("The command is d\n");
Serial.print(" OK!!! TheLED D has hlod ON\n");
while(Serial.available()<=0)
{
mySwitch.send("010101010101010100110000");//遥控器-D按下不放
}
}
}
}
Arduino 433 + 串口的更多相关文章
- C#与Arduino通过串口通信来控制LED灯的状态
一.引言 最近摆弄了一段时间的Arduino,发现Arduino做一些电子类项目.监控.机器人.电子玩具比较容易,并且Arduino与.NET程序集成也不难.接下来介绍一个简单的小程序,C#做的一个W ...
- 手机与Arduino蓝牙串口通讯实验及完整例程
安卓手机与Arduino之间采用蓝牙串口通讯,是很多智能装置和互动装置常用的控制方法,简单而有效,无需网络环境,很实用的技术. 实验采用Arduino UNO板,加了一块1602LCD屏做显示(因为只 ...
- 关于arduino清空串口缓存(转)
在arduino1.0之前的版本 Serial.flush()的作用是是清空串口缓存( dropping received incoming data).但在1.0之后的版本 Serial.flush ...
- 【ARDUINO】串口无法打开问题
1.查看是否串口被锁 sudo arduino ls /var/lock sudo rm /var/lock/LCK..ttyACM* 2.查看arduino安装位置 dpkg -S XXXX 3.原 ...
- Arduino通过串口监视器收发数据
在串口监视器中发送数据,板子收到数据并打印出来. 不需要额外电路,但是板子必须连接电脑,Arduino IDE的串口监视器也需要被打开. 代码 /* 串口事件 当新的串口数据到来时,我们会将它添加到一 ...
- Arduino在串口监视器上输出字母表
程序会在Arduino IDE的串口监视器上输出一个字母表. 不需要额外电路,但是板子必须通过串口线或USB线连接到电脑. 代码 程序在setup()函数中建立串口连接,然后逐行输出a~z的字母I表, ...
- Arduino通讯串口
串口是Arduino与其它设备进行通信的接口 所有的Arduino控制板有至少一个串口(又称作为UART或USART).它通过0(RX)和1(TX)数字引脚经过串口转换芯片连接计算机USB端口与计算机 ...
- [Arduino] 在串口读取多个字符串,并且转换为数字数组
功能如题目.在串口收到逗号分割的6串数字比如100,200,45,4,87,99然后在6个PWM端口3, 5, 6, 9, 10, 11输出对应PWM值代码注释很详细了,就不再说明了. //定义一个c ...
- PMS5003ST+Arduino Nano 串口读取数据
先上代码: 库文件是在guihub上的大神写的https://github.com/jbanaszczyk,我拿来小改下用以支持5003ST #include <Arduino.h> #i ...
随机推荐
- js------保留指定位数小数
// tofix.js文件// params// val: 要处理的数据,Number | String// len: 保留小数位数,位数不足时,以0填充// side: 1|-1 对应 入|舍exp ...
- 《Microsoft SQL Server 2012 T-SQL Fundamentals》
书名 <SQL Server 2012 T-SQL基础教程> 图片 时间 2017-8 学习 每章后面有习题很适合我,看完写sql的能力有质的飞跃好书 http://tsql.soli ...
- flume中的拦截器
Flume中的拦截器(interceptor),用户Source读取events发送到Sink的时候,在events header中加入一些有用的信息,或者对events的内容进行过滤,完成初步的数据 ...
- Vim i和a区别
i是当前位置插入 a是当前文字的后面插入
- Confluence设置MySQL数据库报错:必须使用'READ-COMMITTED'作为默认隔离级别。
解决方案: mysql -u root -p123456 SET GLOBAL tx_isolation='READ-COMMITTED'; mysql数据库创建 1.设置mysql隔离级别 SET ...
- ECMAScript正则表达式6个最新特性
译者按: 还没学好ES6?ECMAScript 2018已经到来啦! 原文:ECMAScript regular expressions are getting better! 作者: Mathias ...
- linux下安装mysql环境
1.在安装apache的时候已经检查了本地没有安装centos自带的mysql,有的话一定要卸载掉,否则可能占用端口 2.准备mysql安装包(注意编译的时候,mysql5.5版本以上的编译和5.5一 ...
- link标签链接CSS和@import加载的区别
link:基本语法 <link rel="stylesheet" href="路径"> @import 基本语法 <style> @im ...
- 从零开始学习html(五)与浏览者交互,表单标签——下
六.使用下拉列表框进行多选 <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type ...
- Android 裁剪人脸
人脸裁剪类 public final class FaceCj { private static BitmapFactory.Options BitmapFactoryOptionsbfo; priv ...