kadir buyuk
/
NRF24_master_slave
TEST EDİLMİŞTİR
Diff: main.cpp
- Revision:
- 1:45ed2ebefd5a
- Parent:
- 0:b643b00c78dc
- Child:
- 2:0914762d8957
--- a/main.cpp Thu Dec 13 09:27:07 2018 +0000 +++ b/main.cpp Fri Jan 18 14:31:17 2019 +0000 @@ -2,7 +2,7 @@ #include <RF24.h> -RF24 device(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, D9); +RF24 device(SPI_MOSI, SPI_MISO, SPI_SCK, D9, SPI_CS); DigitalIn ms(D2); DigitalIn mybutton(USER_BUTTON); const uint64_t pipe_address = 0xF0F0F0F0AA; @@ -14,8 +14,21 @@ device.begin(); + char message[32] = "vv"; + + if (ms){ + device.openWritingPipe(pipe_address); + + } else{ + /*slave*/ + + device.openReadingPipe(1,pipe_address); + device.startListening(); + + } + + while (1){ - char message[32] = "nique ta mere"; if (ms){ @@ -23,7 +36,7 @@ if (mybutton == 0) { transmitter(message); - printf("%s => size : %d\r\n",message,sizeof(message)); + printf("%s => emis : %d\r\n",message,sizeof(message)); wait(0.2); } @@ -31,28 +44,26 @@ } else{ /*slave*/ - receiver(); - + receiver(); } } } void transmitter(char* message){ - device.openWritingPipe(pipe_address); - device.stopListening(); device.write(message,sizeof(message)); } void receiver(){ - device.openReadingPipe(0,pipe_address); - device.startListening(); - if (device.available()){ + + + // if (device.available()){ + char text[32]; device.read(&text, sizeof(text)); if (text[0]!='\0') - printf("%s size : %d\n\r",text,sizeof(text)); - } + printf("%s recu : %d\n\r",text,sizeof(text)); + // } } \ No newline at end of file