SHOW:
|
|
- or go back to the newest paste.
1 | #include <SPI.h> | |
2 | #include <Mirf.h> | |
3 | #include <nRF24L01.h> | |
4 | #include <MirfHardwareSpiDriver.h> | |
5 | #define MAX_BUFF 32 //Буфер приёма-передачи | |
6 | ||
7 | void setup(){ | |
8 | Serial.begin(9600); | |
9 | Mirf.spi = &MirfHardwareSpi; | |
10 | Mirf.init(); | |
11 | ||
12 | Mirf.setRADDR((byte *)"app2"); //Здесь задаём адрес | |
13 | Mirf.payload = MAX_BUFF; //Здесь задаём буфер | |
14 | Mirf.channel = 10; | |
15 | //Это канал приёма-передачи - должен | |
16 | //быть одинаковым у устройств. | |
17 | Mirf.config(); | |
18 | ||
19 | Serial.println("Start.."); | |
20 | } | |
21 | ||
22 | char buff[MAX_BUFF]; | |
23 | int c_count = 0; | |
24 | ||
25 | void loop(){ | |
26 | int i; | |
27 | //sending | |
28 | if (c_count = Serial.available()) { | |
29 | if (c_count <= MAX_BUFF) { | |
30 | for (i=0; i<c_count; i++) { | |
31 | buff[i] = Serial.read(); | |
32 | } | |
33 | } else { | |
34 | for (i=0; i<MAX_BUFF; i++) { | |
35 | buff[i] = Serial.read(); | |
36 | } | |
37 | } | |
38 | buff[i] = 0; | |
39 | Mirf.setTADDR((byte *)"app1"); //Адрес! | |
40 | Serial.print(">"); | |
41 | Mirf.send((uint8_t *)buff); | |
42 | while(Mirf.isSending()){ | |
43 | } | |
44 | Serial.println(buff); | |
45 | } | |
46 | delay(10); | |
47 | //receiving | |
48 | if(Mirf.dataReady()) { | |
49 | Mirf.getData((uint8_t *)buff); | |
50 | Serial.print("<"); | |
51 | Serial.println(buff); | |
52 | } | |
53 | delay(100); | |
54 | } |