Skip to content

Commit

Permalink
reviewed pico examples
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Oct 24, 2021
1 parent 7653422 commit 110b22a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions examples_pico/helloworld_rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* RECEIVER NODE
* Listens for messages from the transmitter and prints them out.
*/
#include "pico/stdlib.h" // printf(), sleep_ms(), getchar_timeout_us(), to_us_since_boot(), get_absolute_time()
#include "pico/bootrom.h" // reset_usb_boot()
#include "pico/stdlib.h" // printf(), sleep_ms(), to_ms_since_boot(), get_absolute_time()
#include <tusb.h> // tud_cdc_connected()
#include <RF24.h> // RF24 radio object
#include <RF24Network.h> // RF24Network network object
Expand Down
9 changes: 4 additions & 5 deletions examples_pico/helloworld_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* TRANSMITTER NODE
* Transmits messages to the reciever every 2 seconds.
*/
#include "pico/stdlib.h" // printf(), sleep_ms(), getchar_timeout_us(), to_us_since_boot(), get_absolute_time()
#include "pico/bootrom.h" // reset_usb_boot()
#include "pico/stdlib.h" // printf(), sleep_ms(), to_ms_since_boot(), get_absolute_time()
#include <tusb.h> // tud_cdc_connected()
#include <RF24.h> // RF24 radio object
#include <RF24Network.h> // RF24Network network object
Expand Down Expand Up @@ -64,12 +63,12 @@ bool setup()
void loop()
{
network.update();
unsigned long now = millis(); // If it's time to send a message, send it!
if (now - last_sent >= interval) {
unsigned long now = to_ms_since_boot(get_absolute_time());
if (now - last_sent >= interval) { // If it's time to send a message, send it!
last_sent = now;

printf("Sending ..\n");
payload_t payload = {millis(), packets_sent++};
payload_t payload = {now, packets_sent++};
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header, &payload, sizeof(payload));
printf("%s.\n", ok ? "ok" : "failed");
Expand Down

0 comments on commit 110b22a

Please sign in to comment.