![](/media/cache/group/V2.png.50x50_q85.png)
reçoive les donées ... nique sa mére
Dependencies: mbed RF24Network RF24
main.cpp@5:ddab03ae19aa, 2019-02-14 (annotated)
- Committer:
- guillaume6544
- Date:
- Thu Feb 14 10:57:11 2019 +0000
- Revision:
- 5:ddab03ae19aa
- Parent:
- 4:93d0253a8a32
- Child:
- 6:4840dd0ef133
rec
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:3982c0e9eda1 | 1 | #include "mbed.h" |
akashvibhute | 0:3982c0e9eda1 | 2 | #include <RF24Network.h> |
akashvibhute | 2:608cf8c5c55e | 3 | #include <RF24.h> |
akashvibhute | 0:3982c0e9eda1 | 4 | |
akashvibhute | 0:3982c0e9eda1 | 5 | Serial pc(USBTX, USBRX); |
guillaume6544 | 5:ddab03ae19aa | 6 | InterruptIn button(D8); |
guillaume6544 | 5:ddab03ae19aa | 7 | |
guillaume6544 | 5:ddab03ae19aa | 8 | PwmOut mypwm(D5); |
akashvibhute | 0:3982c0e9eda1 | 9 | |
wesleytiem | 4:93d0253a8a32 | 10 | RF24 radio(SPI_MOSI, SPI_MISO, SPI_SCK, D9, SPI_CS ); |
akashvibhute | 0:3982c0e9eda1 | 11 | |
akashvibhute | 0:3982c0e9eda1 | 12 | // Network uses that radio |
akashvibhute | 0:3982c0e9eda1 | 13 | RF24Network network(radio); |
akashvibhute | 0:3982c0e9eda1 | 14 | |
akashvibhute | 0:3982c0e9eda1 | 15 | // Address of our node |
akashvibhute | 3:e9c4d66da50c | 16 | const uint16_t this_node = 00; |
akashvibhute | 0:3982c0e9eda1 | 17 | |
akashvibhute | 0:3982c0e9eda1 | 18 | // Address of the other node |
akashvibhute | 3:e9c4d66da50c | 19 | const uint16_t other_node = 01; |
akashvibhute | 0:3982c0e9eda1 | 20 | |
akashvibhute | 0:3982c0e9eda1 | 21 | // When did we last send? |
akashvibhute | 0:3982c0e9eda1 | 22 | unsigned long last_sent; |
akashvibhute | 0:3982c0e9eda1 | 23 | |
akashvibhute | 0:3982c0e9eda1 | 24 | // How many have we sent already |
akashvibhute | 0:3982c0e9eda1 | 25 | unsigned long packets_sent; |
akashvibhute | 0:3982c0e9eda1 | 26 | |
akashvibhute | 0:3982c0e9eda1 | 27 | // Structure of our payload |
akashvibhute | 2:608cf8c5c55e | 28 | struct payload_t |
akashvibhute | 0:3982c0e9eda1 | 29 | { |
akashvibhute | 2:608cf8c5c55e | 30 | unsigned long ms; |
akashvibhute | 2:608cf8c5c55e | 31 | unsigned long counter; |
akashvibhute | 0:3982c0e9eda1 | 32 | }; |
akashvibhute | 0:3982c0e9eda1 | 33 | |
guillaume6544 | 5:ddab03ae19aa | 34 | //interruption du NRF24 |
guillaume6544 | 5:ddab03ae19aa | 35 | void pressed() |
guillaume6544 | 5:ddab03ae19aa | 36 | { |
guillaume6544 | 5:ddab03ae19aa | 37 | mypwm.write(0.5); |
guillaume6544 | 5:ddab03ae19aa | 38 | } |
akashvibhute | 0:3982c0e9eda1 | 39 | |
akashvibhute | 2:608cf8c5c55e | 40 | int main() |
akashvibhute | 0:3982c0e9eda1 | 41 | { |
guillaume6544 | 5:ddab03ae19aa | 42 | button.enable_irq(); |
guillaume6544 | 5:ddab03ae19aa | 43 | button.rise(&pressed); |
guillaume6544 | 5:ddab03ae19aa | 44 | mypwm.period_us(30); |
guillaume6544 | 5:ddab03ae19aa | 45 | mypwm.pulsewidth_us(15); |
guillaume6544 | 5:ddab03ae19aa | 46 | mypwm.write(0.0); |
guillaume6544 | 5:ddab03ae19aa | 47 | |
wesleytiem | 4:93d0253a8a32 | 48 | pc.baud(115200); |
akashvibhute | 0:3982c0e9eda1 | 49 | wait_ms(1000); |
akashvibhute | 2:608cf8c5c55e | 50 | |
akashvibhute | 2:608cf8c5c55e | 51 | pc.printf("mBed RF24Network node\n"); |
akashvibhute | 0:3982c0e9eda1 | 52 | radio.begin(); |
akashvibhute | 0:3982c0e9eda1 | 53 | network.begin(/*channel*/ 90, /*node address*/ this_node); |
akashvibhute | 0:3982c0e9eda1 | 54 | wait_ms(2000); |
akashvibhute | 2:608cf8c5c55e | 55 | |
akashvibhute | 2:608cf8c5c55e | 56 | while(1) |
akashvibhute | 0:3982c0e9eda1 | 57 | { |
akashvibhute | 0:3982c0e9eda1 | 58 | // Pump the network regularly |
akashvibhute | 0:3982c0e9eda1 | 59 | network.update(); |
wesleytiem | 4:93d0253a8a32 | 60 | |
akashvibhute | 0:3982c0e9eda1 | 61 | // Is there anything ready for us? |
akashvibhute | 2:608cf8c5c55e | 62 | while ( network.available() ) |
akashvibhute | 0:3982c0e9eda1 | 63 | { |
akashvibhute | 0:3982c0e9eda1 | 64 | // If so, grab it and print it out |
akashvibhute | 0:3982c0e9eda1 | 65 | RF24NetworkHeader header_rx; |
akashvibhute | 0:3982c0e9eda1 | 66 | payload_t payload_rx; |
akashvibhute | 0:3982c0e9eda1 | 67 | network.read(header_rx,&payload_rx,sizeof(payload_rx)); |
wesleytiem | 4:93d0253a8a32 | 68 | pc.printf("Received packet # %d at %d ms\r\n",payload_rx.counter,payload_rx.ms); |
guillaume6544 | 5:ddab03ae19aa | 69 | |
guillaume6544 | 5:ddab03ae19aa | 70 | wait_ms(2); |
guillaume6544 | 5:ddab03ae19aa | 71 | mypwm.write(0.0); |
akashvibhute | 0:3982c0e9eda1 | 72 | } |
akashvibhute | 1:5be48a9550c3 | 73 | |
akashvibhute | 0:3982c0e9eda1 | 74 | } |
akashvibhute | 2:608cf8c5c55e | 75 | |
akashvibhute | 0:3982c0e9eda1 | 76 | } |