Using the NRF24 class in multiple files


i'm trying access functions within nrf24 library whilst having own sketch broken .ino, .h , .cpp.

however if don't include
code: [select]
rf24 radio(3, 4);
in both .cpp , .ino file, class functions aren't recognised.

however if include
code: [select]
rf24 radio(3, 4);
in both files, load of errors come things being initialised.

how can fix this? i.e. have subroutines.h/.cpp file can work radio class node.ino file can access commands?

the rest of code below if necessary:
node.ino
code: [select]

#include "radiointerface.h"

rf24data volatile ifile;

rf24 radio(3, 4);
void setup() {

  setupradio();
  radio.printdetails();
}

void loop() {
  // nothing now

}


radiointerface.h
code: [select]

//prototype function definition
void setupradio(void);


radiointerface.cpp
code: [select]

#include "arduino.h"
#include "radiointerface.h"

void setupradio(void) {

setupradio();
  radio.begin();                           // setup , configure rf radio
  radio.setchannel(74);                    // set channel
  radio.setpalevel(rf24_pa_high);          // set pa low demonstration. want radio lossy possible example.
  radio.setdatarate(rf24_1mbps);           // raise data rate reduce transmission distance , increase lossiness
  radio.enabledynamicpayloads();           // enable dynamic payloads
  radio.setautoack(1);                     // ensure autoack enabled
  radio.setretries(2, 15);                 // optionally, increase delay between retries. want number of auto-retries high possible (15)
  radio.setcrclength(rf24_crc_16);         // set crc length 16-bit ensure quality of data
  radio.maskirq(1, 1, 0);                  // recieve notifications data recieved;
 
  radio.openwritingpipe(pipes[0]);         // open default reading , writing pipe
  radio.openreadingpipe(1, pipes[1]);
 
  radio.powerup();                         //power radio
  delay(5);
 
  radio.startlistening();                  // start listening
}

damnit forum, wrote long answer forum gave me error.

short answer, declare need it. if need in files, declare there. don't forget ti include library there , not in ino.

or, if want use in both, declare in .ino , pass parameter functions. if want once (for example in begin() call, make pointer.

last option declare extern think that's ugly way it.


Arduino Forum > Using Arduino > Programming Questions > Using the NRF24 class in multiple files


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts