-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.ino
62 lines (53 loc) · 1.36 KB
/
tx.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(10,9); // CE, CSN
const byte address[6] = "00001";
void(* resetFunc) (void) = 0;
void setup() {
// radio.setRetries(2, 8);
//radio.setAutoAck(true);
Serial.begin(250000);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.stopListening();
}
void loop() {
unsigned long timeNow=millis();
char text[] = "Hello World";
sprintf(text,"%u",timeNow);
// Serial.print("Send=");
//Serial.println(text);
radio.write(&text, sizeof(text));
radio.openReadingPipe(0, address);
radio.startListening();
int retry=0;
while(!radio.available())
{
retry++;
if (retry>100){
Serial.println("Resetting");
resetFunc();
}
delay(10);
}
char textRec[32] = "";
radio.read(&textRec, sizeof(textRec));
// Serial.print("Received ack=");
// Serial.println(textRec);
unsigned long timeRecLong;
timeRecLong=atol(textRec);
if (timeRecLong==timeNow){
Serial.print("Diff=");
Serial.println(millis()-timeRecLong);
} else{
Serial.println("OLD");
radio.read(&textRec, sizeof(textRec));
radio.read(&textRec, sizeof(textRec));
radio.read(&textRec, sizeof(textRec));
radio.read(&textRec, sizeof(textRec));
}
radio.stopListening();
radio.openWritingPipe(address);
}