Facebook
From Jakub Tychanycz, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 176
  1.  
  2. // NRF24L01 Module Tutorial - Code for Receiver using Arduino UNO
  3.  
  4. //Include needed Libraries at beginning
  5. #include "nRF24L01.h"
  6. #include "RF24.h"
  7. #include "SPI.h"
  8. #include "Servo.h"
  9.  
  10. Servo MyServo; //Object
  11. RF24 radio(9,10); // NRF24L01 used SPI pins + Pin 9 and 10 on the UNO
  12. const uint64_t pipe = 0xE6E6E6E6E6E6; // Needs to be the same for communicating between 2 NRF24L01
  13.  
  14. void setup(void){
  15.    
  16.   Serial.begin(9600);
  17.   //DC motor and servo
  18.   pinMode(3,OUTPUT);//DC
  19.   pinMode(0,OUTPUT);//DC direction
  20.   pinMode(6,OUTPUT);//Servo
  21.   myservo.attach(6)
  22.  
  23.   radio.begin(); // Start the NRF24L01
  24.   radio.openReadingPipe(1,pipe); // Get NRF24L01 ready to receive
  25.   radio.setPayloadSize(32);
  26.   radio.startListening(); // Listen to see if information received
  27. }
  28.  
  29. void loop(void){
  30.   //Serial.println("Alive");
  31.   while (radio.available()) //signal security
  32.     {
  33.       float PWM1;
  34.       float PWM2;
  35.       float ReceivedMessage[3]={111};
  36.       radio.read(&ReceivedMessage, sizeof(ReceivedMessage)); // Read information from the NRF24L01
  37.       Serial.println(ReceivedMessage[0]); //X
  38.       Serial.println(ReceivedMessage[1]); //Y
  39.       Serial.println(ReceivedMessage[2]); //button
  40.       Serial.println("up");
  41.       //DC contorl
  42.       if(ReceivedMessage[1]<512)//DC direction
  43.         {
  44.           digitalWrite(0,LOW);
  45.           Serial.println(foward);
  46.           }
  47.         else
  48.         {
  49.           digitalWrite(0,HIGH);
  50.           Serial.println(backward);
  51.           }
  52.       PWM1=ReceivedMessage[0]*0,24-122,88  
  53.       PMW1=abs(PWM1);//DC speed value
  54.       analogWrite(3, PWM1);
  55.      
  56.       //Servo control
  57.       PWM2=ReceivedMessage[0]*0,17;
  58.       myservo.write(PWM2);
  59.       }
  60.     delay(100);
  61. }

Replies to NadajnikSilnik rss

Title Name Language When
Re: NadajnikSilnik Jakub Tychanycz cpp 3 Years ago.