Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
- */
- /**
- * Example for Getting Started with nRF24L01+ radios.
- *
- * This is an example of how to use the RF24 class. Write this sketch to two
- * different nodes. Put one of the nodes into 'transmit' mode by connecting
- * with the serial monitor and sending a 'T'. The ping node sends the current
- * time to the pong node, which responds by sending the value back. The ping
- * node can then see how long the whole cycle took.
- */
- #include <SPI.h>
- #include "nRF24L01.h"
- #include "RF24.h"
- #include "printf.h"
- //
- // Hardware configuration
- //
- // Set up nRF24L01 radio on SPI bus plus pins 9 & 10
- RF24 radio(9,10);
- //
- // Topology
- //
- // Radio pipe address
- const uint64_t pipe = 0xF0F0F0F0D2LL;
- //Settings
- char message[] = "DATA OVERGEBRACHT";
- int ART_delay = 15;
- int ART_frequency = 15;
- int channel = 46;
- void setup(void)
- {
- Serial.begin(57600);
- printf_begin();
- //
- // Setup and configure rf radio
- //
- radio.begin();
- // optionally, increase the delay between retries & # of retries
- radio.setRetries(15,15);
- //
- // Open pipe to other nodes for communication
- //
- radio.openReadingPipe(1,pipe);
- radio.startListening();
- radio.printDetails();
- //Settings
- radio.setChannel(channel);
- radio.setPALevel(RF24_PA_MIN);//set output power level RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
- radio.setDataRate(RF24_1MBPS);//set data rate RF24_1MBPS, RF24_2MBPS, RF24_250KBPS
- radio.setRetries(ART_delay, ART_frequency); //ART settings
- }
- void loop(void)
- {
- printf("voor Ontvangen");
- // if there is data ready
- printf("Voor ontvangen.");
- if ( radio.available() )
- {
- printf("Ontvangen");
- // Dump the payloads until we've gotten everything
- unsigned char got_message[17];
- bool done = false;
- while (!done)
- {
- // Fetch the payload, and see if this was the last one.
- done = radio.read( &got_message, sizeof(unsigned char) );
- // Spew it
- printf("Got payload %S...",got_message);
- // Delay just a little bit to let the other unit
- // make the transition to receiver
- delay(20);
- }
- if(strcmp(got_message, message) == 0){
- Serial.print("string are equal.");
- }else{
- Serial.print("string are not equal.");
- }
- // // First, stop listening so we can talk
- // radio.stopListening();
- //
- // // Send the final one back.
- // radio.write( &got_time, 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