Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- RF24 radio(9, 10);
- String NI = String(180, BIN);
- String preambula = "10101010";
- int nrsek = 0;
- int nrwezla = 4;
- int msg;
- const uint64_t pipes[2] = {0xF0F0F0F0E2LL, 0xF0F0F0F0D3LL};
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- radio.begin();
- radio.setRetries(15, 15);
- //radio.openWritingPipe(pipes[1]); // Open pipes for transmitter
- }
- int x = 0;
- void loop() {
- // put your main code here, to run repeatedly:
- if(x == 0)
- {
- x = Serial.read();
- Serial.println(x);
- delay(1000);
- }
- else if(x==49)
- {
- radio.openReadingPipe(1, pipes[0]);
- radio.openWritingPipe(pipes[1]);
- radio.startListening();
- const char text[] = "jakis inny tekst";
- radio.write(&text, sizeof(text));
- //Serial.println(text);
- delay(1000);
- }
- else if(x==50)
- {
- radio.openReadingPipe(1, pipes[1]);
- radio.openWritingPipe(pipes[0]);
- radio.startListening();
- radio.read(msg, 16);
- Serial.println(msg);
- }
- else
- {
- x=0;
- }
- //testobecnosci();
- }
- void testobecnosci()
- {
- for(int i=1;i<=255;i++)
- {
- if(i == nrwezla)
- {
- continue;
- }
- String text = preambula;
- text+=NI;
- String SI = String(i, BIN);
- while(SI.length()!=8)
- {
- SI="0"+SI;
- }
- text+=SI;
- text+="00000001";
- String SN = String(nrsek, BIN);
- while(SN.length()!=8)
- {
- SN="0"+SN;
- }
- text+=SN;
- for(int j=0;j<128;j++)
- {
- text+="0";
- }
- for(int j=0;j<8;j++)
- {
- text+="0";
- }
- Serial.println(text);
- nrsek++;
- if(nrsek>255)
- {
- nrsek = 0;
- }
- radio.write(&text, sizeof(text));
- delay(100);
- }
- }
- void obecnosc()
- {
- radio.stopListening();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement