Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include "nRF24L01.h"
- #include "RF24.h"
- #include "printf.h"
- RF24 radio(9,10);
- // Radio pipe addresses for the 2 nodes to communicate.
- const uint64_t pipes[2] = { 0xF0F0F0F0E1EE, 0xF0F0F0F0D2EE };
- // [OPDRACHT WEEK 3]
- int LED_OUTPUT = 7;
- long startMillis;
- void setup(void)
- {
- Serial.begin(57600);
- printf_begin();
- // [OPDRACHT WEEK 3]
- pinMode(LED_OUTPUT, OUTPUT);
- //
- // Setup and configure rf radio
- //
- radio.begin();
- // optionally, increase the delay between retries & # of retries
- radio.setRetries(15,15);
- radio.openWritingPipe(pipes[1]);
- radio.openReadingPipe(1,pipes[0]);
- // OPDRACHT [Week 4, 4.B]
- // radio.setChannel(3);
- // OPDRACHT [Week 4, 4.C]
- // radio.setDataRate(RF24_2MBPS);
- radio.startListening();
- radio.printDetails();
- }
- void loop(void)
- {
- // if there is data ready
- if ( radio.available() )
- {
- // Dump the payloads until we've gotten everything
- unsigned long buttonState = 0;
- bool done = false;
- while (!done)
- {
- // Fetch the payload, and see if this was the last one.
- done = radio.read( &buttonState, sizeof(unsigned long) );
- // Spew it
- printf("Got payload %lu...",buttonState);
- // [OPDRACHT WEEK 3]
- // off because of data with the other week projects
- // digitalWrite(LED_OUTPUT, buttonState);
- }
- // First, stop listening so we can talk
- radio.stopListening();
- // Send the final one back.
- radio.write( &buttonState, sizeof(unsigned long) );
- printf("Sent response.\n\r");
- // Now, resume listening so we catch the next packets.
- radio.startListening();
- }
- }
- // vim:cin:ai:sts=2 sw=2 ft=cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement