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
Diff: main.cpp
- Revision:
 - 4:d7a0a07f21f3
 - Parent:
 - 3:d605536db315
 
--- a/main.cpp	Thu Nov 05 05:59:18 2015 +0000
+++ b/main.cpp	Thu May 20 07:26:02 2021 +0000
@@ -1,14 +1,15 @@
 #include "mbed.h"
 #include <RF24Network.h>
 #include <RF24.h>
+#include "isen32_board.h"
 
-Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);        // 9600 baud par défaut
 
-#define nrf_CE      D9
-#define nrf_CSN     D10
-#define spi_SCK     D3
-#define spi_MOSI    D4
-#define spi_MISO    D5
+#define nrf_CE      PB_3        // D3 sur connecteur Arduino        
+#define nrf_CSN     PB_12
+#define spi_MOSI    PB_15
+#define spi_MISO    PB_14
+#define spi_SCK     PB_13
 
 RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
 
@@ -22,7 +23,7 @@
 const uint16_t other_node = 00;
 
 // How often to send payload packet to the other unit
-const unsigned long interval = 100; //ms
+const unsigned long interval = 1000; //ms
 
 // When did we last send?
 unsigned long last_sent;
@@ -35,24 +36,38 @@
 // Structure of our payload
 struct payload_t 
 {
-    unsigned long ms;
-    unsigned long counter;
+//    unsigned long ms;
+//    unsigned long counter;
+    uint8_t num;
+    uint8_t del;
 };
 
+struct _node
+{
+    uint8_t num;
+    uint8_t del;
+};
 
 int main()
 {
-    pc.baud(921600);
+    _node node;
+       
+    BTN1.mode(PullUp);    // Resist interne Pull up
+    pc.baud(9600);
     wait_ms(1000);
 
-    pc.printf("mBed RF24Network node: Tx\n");
+    pc.printf("mBed RF24Network node : 01\r\n");
     radio.begin();
     network.begin(/*channel*/ 90, /*node address*/ this_node);
     wait_ms(2000);
     t.start();
     t_packet.start();
+    
     while(1) 
     {
+        // Refresh Dels
+        Set_8Dels(node.del);
+        
         // Pump the network regularly
         network.update();
 
@@ -62,21 +77,38 @@
         {
             t.reset();
 
-            pc.printf("Sending...");
+            pc.printf("Envoi...");
             payload_t payload_tx;
-            payload_tx.ms = t_packet.read_ms();
-            payload_tx.counter = packets_sent++;
+            if(!BTN1)
+                payload_tx.num = 02;
+            else
+                payload_tx.num = 00;
+                
+            payload_tx.del++;
 
 
             RF24NetworkHeader header_tx(/*to node*/ other_node);
             bool ok = network.write(header_tx,&payload_tx,sizeof(payload_tx));
             if (ok)
-                pc.printf("ok.\n");
+                pc.printf("%d ok.\r\n",payload_tx.del);
             else
-                pc.printf("failed.\n");
+                pc.printf("erreur.\r\n");
+                
+                
         }
-
-
+        while ( network.available() ) 
+        {
+            // If so, grab it and print it out
+            RF24NetworkHeader header_rx;
+            payload_t payload_rx;
+            network.read(header_rx,&payload_rx,sizeof(payload_rx));
+ //           pc.printf("Received packet # %d at %d ms\r\n",payload_rx.counter,payload_rx.ms);
+            pc.printf("Node %d del %d\r\n",payload_rx.num,payload_rx.del);
+            
+            if (payload_rx.num == 01)
+            {
+                node.del = payload_rx.del;
+            }
+         }
     }
-
 }
\ No newline at end of file