Does nRF24L01.h work with millis(); ?

Hello guys

I have Arduino Nano - ATmega168. Joystick example from nRF24L01 works fine with potenciometers, both receive and transmit. But i have problem with millis() function. When i uncomment row:

//radio.write( joystick, sizeof(joystick) );

it stops work. Below is my code. Where is pls problem? Thx a lot guys.

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN 9
#define CSN_PIN 10
#define JOYSTICK_0 A0
#define JOYSTICK_1 A1
#define JOYSTICK_2 A2
#define JOYSTICK_3 A3
#define JOYSTICK_4 A4
#define JOYSTICK_5 A5

const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int joystick[6];
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
int interval = 15;
int pos = 0;
bool posRaise = true;

void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
Serial.println("Conected OK");
}

void loop()
{
currentMillis = millis();
Serial.println("X pos.:");
Serial.println(joystick[0]);
timingLoop();
//radio.write( joystick, sizeof(joystick) );
}

void timingLoop() {
if (currentMillis - previousMillis >= interval) {
if (posRaise) {
pos ++;
joystick[0] = pos;
if (pos > 179) {posRaise = false;}
}
else {
pos --;
joystick[0] = pos;
if (pos < 1) {posRaise = true;}
}
previousMillis = currentMillis;
}
}

Regards Petr

You'll need to explain what "it stops work" means. There doesn't seem to be any reason for that code to stop working because you try to use the radio.

Sorry about my inaccurate expression.

I mean function Serial.println(joystick[0]); is printing value of joystick[0] = pos; as function void timingLoop() count this variable.

When i uncomment //radio.write( joystick, sizeof(joystick) ); Serial.println(joystick[0]); stops printing like before and prints only 0 value. It seems timingLoop() stops counting.

Thank you for helping me :slight_smile:
Regards Petr

I suggest you use the TMRh20 version of the RF24 library. There is some problem with the .write() function in the earlier ManiacBug version when there is an interval between successive write()s

I did get the ManiacBug version to work by disabling the call to powerDown() near the bottom of the .write() function in RF24.cpp. I never did figure out why that solved the problem because I switched to the TMRh20 version.

...R