Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <SPI.h>
  2. #include "nRF24L01.h"
  3. #include "RF24.h"
  4. #include "printf.h"
  5.  
  6. RF24 radio(9,10);
  7.  
  8. // Radio pipe addresses for the 2 nodes to communicate.
  9. const uint64_t pipes[2] = { 0xF0F0F0F0E1EE, 0xF0F0F0F0D2EE };
  10.  
  11. // [OPDRACHT WEEK 3]
  12. int LED_OUTPUT = 7;
  13.  
  14. long startMillis;
  15.  
  16. void setup(void)
  17. {
  18. Serial.begin(57600);
  19. printf_begin();
  20.  
  21. // [OPDRACHT WEEK 3]
  22. pinMode(LED_OUTPUT, OUTPUT);
  23. //
  24. // Setup and configure rf radio
  25. //
  26. radio.begin();
  27.  
  28. // optionally, increase the delay between retries & # of retries
  29. radio.setRetries(15,15);
  30.  
  31. radio.openWritingPipe(pipes[1]);
  32. radio.openReadingPipe(1,pipes[0]);
  33.  
  34. // OPDRACHT [Week 4, 4.B]
  35. // radio.setChannel(3);
  36. // OPDRACHT [Week 4, 4.C]
  37. // radio.setDataRate(RF24_2MBPS);
  38. radio.startListening();
  39. radio.printDetails();
  40. }
  41.  
  42. void loop(void)
  43. {
  44. // if there is data ready
  45. if ( radio.available() )
  46. {
  47. // Dump the payloads until we've gotten everything
  48. unsigned long buttonState = 0;
  49. bool done = false;
  50. while (!done)
  51. {
  52. // Fetch the payload, and see if this was the last one.
  53. done = radio.read( &buttonState, sizeof(unsigned long) );
  54. // Spew it
  55. printf("Got payload %lu...",buttonState);
  56.  
  57. // [OPDRACHT WEEK 3]
  58. // off because of data with the other week projects
  59. // digitalWrite(LED_OUTPUT, buttonState);
  60.  
  61. }
  62. // First, stop listening so we can talk
  63. radio.stopListening();
  64.  
  65. // Send the final one back.
  66. radio.write( &buttonState, sizeof(unsigned long) );
  67. printf("Sent response.\n\r");
  68.  
  69. // Now, resume listening so we catch the next packets.
  70. radio.startListening();
  71. }
  72.  
  73. }
  74. // vim:cin:ai:sts=2 sw=2 ft=cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement