Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed RF24Network RF24
main.cpp
00001 #include "mbed.h" 00002 #include <RF24Network.h> 00003 #include <RF24.h> 00004 00005 Serial pc(USBTX, USBRX); 00006 InterruptIn button(D4); 00007 00008 PwmOut mypwm(D5); 00009 00010 RF24 radio(SPI_MOSI, SPI_MISO, SPI_SCK, D9, SPI_CS ); 00011 00012 DigitalIn A(D8); 00013 DigitalIn B(D7); 00014 DigitalIn C(D6); 00015 00016 00017 // Network uses that radio 00018 RF24Network network(radio); 00019 00020 00021 // Address of our node 00022 uint16_t this_node; 00023 00024 // Address of the other node 00025 const uint16_t other_node = 00; 00026 00027 // When did we last send? 00028 unsigned long last_sent; 00029 00030 // How many have we sent already 00031 unsigned long packets_sent; 00032 00033 // Structure of our payload 00034 struct payload_t 00035 { 00036 unsigned long ms; 00037 unsigned long counter; 00038 }; 00039 00040 //interruption du NRF24 00041 void pressed() 00042 { 00043 mypwm.write(0.5); 00044 } 00045 00046 int main() 00047 { 00048 button.enable_irq(); 00049 button.rise(&pressed); 00050 mypwm.period_us(40); 00051 mypwm.pulsewidth_us(20); 00052 mypwm.write(0.0); 00053 00054 if((!A.read()) && (!B.read()) && (C.read()) ) this_node = 01; 00055 else if(!(A.read()) && (B.read()) && !(C.read()) ) this_node = 02; 00056 else this_node = 03; 00057 00058 pc.baud(115200); 00059 wait_ms(500); 00060 00061 pc.printf("mBed RF24Network node\r\n"); 00062 radio.begin(); 00063 network.begin(/*channel*/ 90, /*node address*/ this_node); 00064 wait_ms(1000); 00065 00066 while(1) 00067 { 00068 // Pump the network regularly 00069 network.update(); 00070 00071 // Is there anything ready for us? 00072 while ( network.available() ) 00073 { 00074 // If so, grab it and print it out 00075 RF24NetworkHeader header_rx; 00076 payload_t payload_rx; 00077 network.read(header_rx,&payload_rx,sizeof(payload_rx)); 00078 pc.printf("Received packet # %d at %d ms\r\n",payload_rx.counter,payload_rx.ms); 00079 00080 wait_us(1750); 00081 mypwm.write(0.0); 00082 } 00083 00084 } 00085 00086 } 00087
Generated on Wed Jul 13 2022 17:46:27 by
1.7.2