I'm trying to code a simple transmitter - Receiver program with nRF24L01
Very simple code. Compiles. But when I try to test it using serial monitor. But only the first character is printed on the screen just once.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
int smth[1]; // the transmitter data
int x=0; // the copy of the receiver data
char rec[1]; //the receiver data
int ledPin = 3; // choose the pin for the LED
int inPin = 7; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
radio.begin();
radio.openWritingPipe(pipe); //originally transmitter
}
void loop(){
val = digitalRead(inPin); // read input value
if (val==HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, HIGH); // turn LED OFF
Serial.println('1');
smth[0] = '1';
radio.write(smth, sizeof(smth));
} else {
digitalWrite(ledPin, LOW); // turn LED ON
Serial.println('0');
smth[0] = '0';
radio.write(smth, sizeof(smth));
}
}
Serial Monitor :
0
Instead of printing a zeros for infinite time till I change the mode of the switch, even though if I change the mode of the switch from low to high, nothing is printed on the screen.
I'm using Library for instance http://playground.arduino.cc/InterfacingWithHardware/Nrf24L01
Any help?
int smth[1];
tobyte smth[1];
. – Gerben Dec 14 '15 at 13:19