![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dd
Dependencies: xtoff2 RF24Network mbed
Fork of xtoff3 by
Diff: main.cpp
- Revision:
- 4:7ebc3b421306
- Parent:
- 3:e9c4d66da50c
- Child:
- 6:6a82110ff393
--- a/main.cpp Thu Nov 05 06:32:20 2015 +0000 +++ b/main.cpp Mon Feb 12 16:50:45 2018 +0000 @@ -1,66 +1,33 @@ +/** + Main.cpp + Purpose: main class + + @author Pieter Berteloot +*/ #include "mbed.h" -#include <RF24Network.h> -#include <RF24.h> +#include "Ontvanger.h" + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); Serial pc(USBTX, USBRX); -#define nrf_CE D9 -#define nrf_CSN D10 -#define spi_SCK D3 -#define spi_MOSI D4 -#define spi_MISO D5 - - -RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN ); - -// Network uses that radio -RF24Network network(radio); - -// Address of our node -const uint16_t this_node = 00; - -// Address of the other node -const uint16_t other_node = 01; - -// When did we last send? -unsigned long last_sent; - -// How many have we sent already -unsigned long packets_sent; - -// Structure of our payload -struct payload_t -{ - unsigned long ms; - unsigned long counter; -}; - +Ontvanger receive; int main() { - pc.baud(921600); - wait_ms(1000); - - pc.printf("mBed RF24Network node\n"); - radio.begin(); - network.begin(/*channel*/ 90, /*node address*/ this_node); - wait_ms(2000); - - while(1) - { - // Pump the network regularly - network.update(); - - // Is there anything ready for us? - 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\n",payload_rx.counter,payload_rx.ms); + pc.baud(9600); + pc.printf("Ontvangger: \r\n"); + while(1) { + receive.update(); + while (receive.available()) { + payload_t payload; + payload = receive.read(); + pc.printf("Received packet -- Reed: %d --- %d mg \r\n",payload.reedsensor,payload.milligram); + myled1 = myled2 = myled3 = myled4= payload.reedsensor; } - + myled1 = myled2 = myled3 = myled4= 0; } - } \ No newline at end of file