Advertisement
Guest User

Untitled

a guest
Aug 13th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. // L298N - Version: Latest
  2. #include <SPI.h>
  3. #include <nRF24L01.h>
  4. #include <RF24.h>
  5.  
  6. #define jB1 5 // Joystick button 1
  7. #define jB2 4 // Joystick button 2
  8. #define b1 3 // Button 1
  9. #define b2 2 // Button 2
  10. #define b3 6 // Button 3
  11. #define b4 9 // Button 4
  12.  
  13. RF24 radio(7, 8); // nRF24L01 (CE, CSN)
  14. const byte address[6] = "00001"; // Address
  15.  
  16.  
  17. // Max size of this struct is 32 bytes - NRF24L01 buffer limit
  18. struct Data_Package {
  19. byte j1PotX;
  20. byte j1PotY;
  21. byte j2PotX;
  22. byte j2PotY;
  23. byte button1;
  24. byte button2;
  25. byte button3;
  26. byte button4;
  27. };
  28.  
  29. Data_Package data; //Create a variable with the above structure
  30.  
  31. void setup() {
  32. Serial.begin(115200);
  33. Serial.println("receiver");
  34. radio.begin();
  35. radio.openWritingPipe(address);
  36. radio.setPALevel(RF24_PA_MAX);
  37. radio.setDataRate(RF24_250KBPS);
  38. radio.stopListening();
  39.  
  40. }
  41.  
  42. void loop() {
  43.  
  44. data.j1PotX = analogRead(A5); // Convert the analog read value from 0 to 1023 into a BYTE value from 0 to 255
  45. data.j1PotY = analogRead(A4);
  46. data.j2PotX = analogRead(A2);
  47. data.j2PotY = analogRead(A1);
  48. // Read all digital inputs
  49. data.button1 = digitalRead(b1);
  50. data.button2 = digitalRead(b2);
  51. data.button3 = digitalRead(b3);
  52. data.button4 = digitalRead(b4);
  53.  
  54. radio.write(&data, sizeof(Data_Package)); // Write and send the data to the receiver
  55.  
  56. Serial.println(data.j1PotX);
  57. Serial.println(data.j1PotY);
  58. Serial.println(data.j2PotX);
  59. Serial.println(data.j2PotY);
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement