-
Notifications
You must be signed in to change notification settings - Fork 0
/
teste.cpp
48 lines (40 loc) · 989 Bytes
/
teste.cpp
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
#include <cstdlib>
#include <iostream>
#include "../RF24.h"
using namespace std;
// spi device, spi speed, ce gpio pin
RF24 radio("/dev/spidev0.0",8000000,25);
void setup(void)
{
// init radio for reading
radio.begin();
radio.enableDynamicPayloads();
radio.setAutoAck(1);
radio.setRetries(15,15);
radio.setDataRate(RF24_1MBPS);
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(76);
radio.setCRCLength(RF24_CRC_16);
radio.openReadingPipe(1,0xF0F0F0F0E1LL);
radio.startListening();
}
void loop(void)
{
// 32 byte character array is max payload
char receivePayload[32];
while (radio.available())
{
// read from radio until payload size is reached
uint8_t len = radio.getDynamicPayloadSize();
radio.read(receivePayload, len);
// display payload
cout << receivePayload << endl;
}
}
int main(int argc, char** argv)
{
setup();
while(1)
loop();
return 0;
}