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