zoukankan      html  css  js  c++  java
  • Arduino Wireless Communication – NRF24L01 Tutorial(arduino无线通信---NRF24L01教程)

    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));
      }
    }
     
  • 相关阅读:
    SQL Server 作业的备份
    SQL Server 非sysadmin调用扩展函数
    SQL Server 性能调优(io)
    What is allocation bottleneck?
    SQL Server 2008 性能调优 optimize for ad hoc workloads
    执行计划的缓存
    sql server 2000 sp3 数据库复制 修改sp_MSget_repl_commands
    Xcode4.5出现时的OC新语法
    NSZombieEnabled ,解决EXC_BAD_ACCESS错误的一种方法
    有关View的几个基础知识点IOS开发
  • 原文地址:https://www.cnblogs.com/anandexuechengzhangzhilu/p/10706373.html
Copyright © 2011-2022 走看看