RF24 library question - what these lines do?


hello,
with reference joystick example uses nrf24l01's rf24.h library send , receive joystick analog values - can explain these lines do?  i'm quoting few lines in post, include entire sketch @ bottom.

1) 
quote

// note: "ll" @ end of constant "longlong" type
const uint64_t pipe = 0xe8e8f0f0e1ll; // define transmit pipe


in mirf library, receiver has "name", senders can identify receiver data meant for.  purpoase of "pipe" definition in rf24 library?  sender , receiver have use same pipe value?

2)
quote
if ( radio.available() )


does available() return true when there new packet?  if sender doesn't send anything, keeps printing "no radio available"?

3) 
quote

    while (!done)
    {
      // fetch data payload
      done = radio.read( joystick, sizeof(joystick) );
      serial.print("x = ");
      serial.print(joystick[0]);
      serial.print(" y = ");     
      serial.println(joystick[1]);
    }


why in while loop?  while done false (meaning hasn't read data yet), won't keep printing trash joystick[0] , joystick[1]??  shouldn't serial.print outside while loop?  else we're expecting read() command run once, in case don't understand purpose of loop.

i know reading other people's code isn't fun, appreciate insights.

from http://arduino-info.wikispaces.com/nrf24l01-2.4ghz-howto

code: [select]

/*-----( import needed libraries )-----*/
#include <spi.h>
#include <nrf24l01.h>
#include <rf24.h>
/*-----( declare constants , pin numbers )-----*/
#define ce_pin   9
#define csn_pin 10

// note: "ll" @ end of constant "longlong" type
const uint64_t pipe = 0xe8e8f0f0e1ll; // define transmit pipe


/*-----( declare objects )-----*/
rf24 radio(ce_pin, csn_pin); // create radio
/*-----( declare variables )-----*/
int joystick[2];  // 2 element array holding joystick readings

void setup()   /****** setup: runs once ******/
{
  serial.begin(9600);
  delay(1000);
  serial.println("nrf24l01 receiver starting");
  radio.begin();
  radio.openreadingpipe(1,pipe);
  radio.startlistening();;
}//--(end setup )---


void loop()   /****** loop: runs ******/
{
  if ( radio.available() )
  {
    // read data payload until we've received everything
    bool done = false;
    while (!done)
    {
      // fetch data payload
      done = radio.read( joystick, sizeof(joystick) );
      serial.print("x = ");
      serial.print(joystick[0]);
      serial.print(" y = ");     
      serial.println(joystick[1]);
    }
  }
  else
  {   
      serial.println("no radio available");
  }



Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > RF24 library question - what these lines do?


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support