mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2025-09-17 17:32:25 -07:00
switch to setup for Arduino Boards Manager
This commit is contained in:
4
digistump-sam/libraries/RF24Network/examples/helloworld_tx/.gitignore
vendored
Normal file
4
digistump-sam/libraries/RF24Network/examples/helloworld_tx/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
version.h
|
||||
output/
|
||||
ojam/
|
||||
.*.swp
|
@@ -0,0 +1,6 @@
|
||||
SubDir TOP libraries RF24Network examples helloworld_tx ;
|
||||
|
||||
LOCATE_SOURCE = $(SUBDIR)/$(PINS) ;
|
||||
LOCATE_TARGET = $(SUBDIR)/$(PINS) ;
|
||||
|
||||
ArduinoWithLibs Main : RF24Network RF24 Tictocs SPI ;
|
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simplest possible example of using RF24Network
|
||||
*
|
||||
* TRANSMITTER NODE
|
||||
* Every 2 seconds, send a payload to the receiver node.
|
||||
*/
|
||||
|
||||
#include <RF24Network.h>
|
||||
#include <RF24.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// nRF24L01(+) radio attached using Getting Started board
|
||||
RF24 radio(9,10);
|
||||
|
||||
// Network uses that radio
|
||||
RF24Network network(radio);
|
||||
|
||||
// Address of our node
|
||||
const uint16_t this_node = 1;
|
||||
|
||||
// Address of the other node
|
||||
const uint16_t other_node = 0;
|
||||
|
||||
// How often to send 'hello world to the other unit
|
||||
const unsigned long interval = 2000; //ms
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(57600);
|
||||
Serial.println("RF24Network/examples/helloworld_tx/");
|
||||
|
||||
SPI.begin();
|
||||
radio.begin();
|
||||
network.begin(/*channel*/ 90, /*node address*/ this_node);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// Pump the network regularly
|
||||
network.update();
|
||||
|
||||
// If it's time to send a message, send it!
|
||||
unsigned long now = millis();
|
||||
if ( now - last_sent >= interval )
|
||||
{
|
||||
last_sent = now;
|
||||
|
||||
Serial.print("Sending...");
|
||||
payload_t payload = { millis(), packets_sent++ };
|
||||
RF24NetworkHeader header(/*to node*/ other_node);
|
||||
bool ok = network.write(header,&payload,sizeof(payload));
|
||||
if (ok)
|
||||
Serial.println("ok.");
|
||||
else
|
||||
Serial.println("failed.");
|
||||
}
|
||||
}
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
Reference in New Issue
Block a user