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