Hi,
first I need to thank you becouse the NRF24L01 moduls are working. Thank you for the help in the program I sent you in the last topic. But now I have anoter problem. When I unplug the arduino like I will shut down the motorbike, and then I plug it in the reciver doesn't start to recive data until I turn on the Serial window in top right corner. I did put in the serial.print command to see if inputs are getting some signal, but it doesn't start reciving signal if the serial.print command is not included in the program?
Can you please help me once more.
I will put the program for reciving once more down in this message.
Thank you for your time.
Matej
/*2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
Brakes = D2
Left Blinker = D3
Right Blinker = D4*/
/-----( Import needed libraries )-----/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/-----( Declare Constants and Pin Numbers )-----/
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/-----( Declare objects )-----/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/-----( Declare Variables )-----/
int input[3];
int ledStateLeft = LOW;
int ledStateRight = LOW;
unsigned long previousMillisLeft = 0;
unsigned long previousMillisRight = 0;
unsigned long previousMillisLed = 0;
int done;
const long interval = 500;
void setup() /****** SETUP: RUNS ONCE ******/
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
Serial.print(input[2]);
Serial.print('\n');
unsigned long currentMillis = millis();
if ( radio.available() )
{
// Fetch the data payload
radio.read(input, sizeof(input));
/* Serial.println(input[0]);
Serial.println(input[1]);
Serial.println(input[2]);
*/
if (input[0] >= 505)
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
else
{ digitalWrite(2, LOW);
}
if (input[1] > 505)
{
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
if(currentMillis - previousMillisLeft >= interval) {
// save the last time you blinked the LED
previousMillisLeft = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledStateLeft == LOW)
ledStateLeft = HIGH;
else
ledStateLeft = LOW;
// set the LED with the ledState of the variable:
digitalWrite(3, ledStateLeft);
}
}
else {
ledStateLeft = LOW;
// set the LED with the ledState of the variable:
digitalWrite(3, ledStateLeft);
}
if (input[2] > 505)
{
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
if(currentMillis - previousMillisRight >= interval) {
// save the last time you blinked the LED
previousMillisRight = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledStateRight == LOW)
ledStateRight = HIGH;
else
ledStateRight = LOW;
digitalWrite(4, ledStateRight);
}
}
else {
ledStateRight = LOW;
// set the LED with the ledState of the variable:
digitalWrite(4, ledStateRight);
}
} //end if radio available
}//--(end main loop )---
/-----( Declare User-written Functions )-----/
//NONE
//( THE END )**
