arduino下nrf24l01库文件及相关说明

库的说明文档

https://tmrh20.github.io/RF24/

库的源代码github下载页面

https://tmrh20.github.io/RF24/ 

Arduino IDE直接安装库文件

直接在arduino库管理器中搜索“rf24”关键字 选择TMRh20作者的版本安装

发送的源码
/*
* Arduino Wireless Communication Tutorial
*     Example 2 - Transmitter Code
*               
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
 
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
 
#define led 12
 
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
boolean buttonState = 0;
 
void setup() {
  pinMode(12, OUTPUT);
  radio.begin();
  radio.openWritingPipe(addresses[1]); // 00001
  radio.openReadingPipe(1, addresses[0]); // 00002
  radio.setPALevel(RF24_PA_MIN);
}
 
void loop() {
  delay(5);
 
  radio.stopListening();
  int potValue = analogRead(A0);
  int angleValue = map(potValue, 0, 1023, 0, 180);
  radio.write(&angleValue, sizeof(angleValue));
 
  delay(5);
  radio.startListening();
  while (!radio.available());
  radio.read(&buttonState, sizeof(buttonState));
  if (buttonState == HIGH) {
    digitalWrite(led, HIGH);
  }
  else {
    digitalWrite(led, LOW);
  }
}
 
 
接受的源码
/*
* Arduino Wireless Communication Tutorial
*     Example 2 - Receiver Code
*               
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define button 4
RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};
Servo myServo;
boolean buttonState = 0;
void setup() {
  pinMode(button, INPUT);
  myServo.attach(5);
  radio.begin();
  radio.openWritingPipe(addresses[0]); // 00002
  radio.openReadingPipe(1, addresses[1]); // 00001
  radio.setPALevel(RF24_PA_MIN);
}
void loop() {
  delay(5);
  radio.startListening();
  if ( radio.available()) {
    while (radio.available()) {
      int angleV = 0;
      radio.read(&angleV, sizeof(angleV));
      myServo.write(angleV);
    }
    delay(5);
    radio.stopListening();
    buttonState = digitalRead(button);
    radio.write(&buttonState, sizeof(buttonState));
  }
}
 

Arduino Wireless Communication – NRF24L01 Tutorial(arduino无线通信---NRF24L01教程)的更多相关文章

  1. Arduino + RFID 读取 IC 卡 Arduino uno中获得RFID的UID 并通过串口转发RFID卡号

    RFID简介:射频识别即RFID(Radio Frequency IDentification)技术,又称无线射频识别,是一种通信技术,可通过无线电讯号识别特定目标并读写相关数据,而无需识别系统与特定 ...

  2. 控制Arduino的利器-Windows Remote Arduino

    1. 概述 相信很多朋友已经在玩 Arduino了,而且一般都是使用官方的Arduino IDE来写程序控制Arduino硬件.为了能够实现更加方便的控制,微软在Windows IoT计划中推出了Wi ...

  3. 基于Proteus仿真的Arduino学习(1)——Arduino Uno最小系统及LED的简单使用

    一.前言:  A.Arduino简介 Arduino是由一个欧洲开发团队于2005年冬季开发.其成员包括Massimo Banzi.David Cuartielles.Tom Igoe.Gianluc ...

  4. [转] 控制Arduino的利器-Windows Remote Arduino

    原文地址:控制Arduino的利器-Windows Remote Arduino 1. 概述 相信很多朋友已经在玩 Arduino了,而且一般都是使用官方的Arduino IDE来写程序控制Ardui ...

  5. Arduino基础入门篇-进入Arduino的世界

    写在前面,首先是发现有网友对Arduino做了介绍,而且介绍比较清晰到位,就引用过来了. 文章出处:https://blog.csdn.net/TonyIOT/article/details/8091 ...

  6. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.7 Adding a wms layer

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.7 Adding a wms layer 前言 Add OGC WMS Layers( ...

  7. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.6 Defining Projections and Extents

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.6 Defining Projections and Extents 一.前言 当在m ...

  8. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.5 Adding a raster layer

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.5 Adding a  raster layer 一.前言 MapServer不仅支持 ...

  9. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map 一.前言 MapServer拥有非常灵活的标签 ...

随机推荐

  1. 最简单-转换MBR为GPT

    Windows Server 2016可能没有这个 mbr2gpt 这个软件,可以从Windows 10 的C:\Windows\System32 目录下面复制到 Windows Server 201 ...

  2. 从ofo到乐视,变卖资产好过冬靠谱吗?

    今年年底,有很多人"被迫"离职.他们为了应对生活压力和找工作的不确定性,尝试在二手平台上卖出自己的奢侈品或心爱之物,以期度过潜在的难关.而对于很多企业来说,这个冬天也非常冷.依靠常 ...

  3. android中的简单animation(三)accelerate(加速),decelerate(减速),anticipate,overshoot,bounce

    animation_3.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...

  4. 看完本文,Essay写作再也不需要凑字数

    很多同学都说过自己写论文的时候出现“词穷”的情况,无奈只能靠“胡编乱造”来凑字数写出开头段,这其实是大家的阅读量没有达到要求.但不能因为出现这种情况就对自己的论文不负责任,否则你的论文分数可能就不会对 ...

  5. 在 linux 中遇到 OSError: inotify watch limit reached 错误

    检查系统当前限制,默认应该是 8192: cat /proc/sys/fs/inotify/max_user_watches 可根据需要调整系统限制,但是目前还不知道如何查看每个进程对 watch 的 ...

  6. java.neo的ByteBuffer与Netty 的ByteBuf

    JDK的ByteBuffer的缺点: 1.final byte[] hb;这是JDKde ByteBuffer对象中用于存储数据的对象声明;可以看到,其字节数组是被声明为final的,也就是长度是固定 ...

  7. F. Fairness 分硬币最大差值最小

    F. Fairness time limit per test 2.0 s memory limit per test 64 MB input standard input output standa ...

  8. linux扩容空间,再扩容文件系统

    Linux磁盘空间进行扩容 参考博客 http://blog.csdn.net/dingchenxixi/article/details/50986472 http://blog.sina.com.c ...

  9. 中兴将用“加减乘除”建立理想 5G 网络

      6 月 28 日,MWC 2019 上海展期间,中兴通讯执行董事.总裁徐子阳发表演讲表示,面对 5G 建网大势,要看破大势,不破不立.为此中兴将用“加减乘除”建立理想 5G 网络. 何为“加减乘除 ...

  10. 037-PHP如何返回闭包函数实例

    <?php /*: 如何返回闭包函数实例*/ # 直接调用将不会输出$txt的内容 function demo() { $txt = '我爱PHP'; $func = function () u ...