Skip to content

Instantly share code, notes, and snippets.

@FreekingDean
Last active January 4, 2016 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FreekingDean/8592831 to your computer and use it in GitHub Desktop.
Save FreekingDean/8592831 to your computer and use it in GitHub Desktop.
Receiver
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <RF24_config.h>
/*
* This is a simple arduino module set to be a transmitter, currently for
* firework Efuse Slats && holiday lightshow spectacular.
* Author: Dean Galvin
* Creation Date: 12-9-2013
* Last Updated: 1-22-2014
* Version 0.01
*/
//I attempt to make all constants up
//outside the code below.
//Setup RDF24 pins SPI 50-52
RF24 radio(9,10);
//
// Topology
//
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
//
// Role management
//
// Set up role. This sketch uses the same software for all the nodes
// in this system. Doing so greatly simplifies testing.
//
// The various roles supported by this sketch
typedef enum { role_ping_out = 1, role_pong_back } role_e;
// The debug-friendly names of those roles
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
// The role of the current running sketch
role_e role = role_pong_back;
int pingWait = 10000;
int pingTime = pingWait-1;
long pingSent = 0;
bool connected = false;
bool timedOut = false;
byte pingout[] = {0x05, 0x00, 0x00};
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(57600);
radio.begin();
radio.setRetries(0, 15);
radio.setPayloadSize(8);
radio.startListening();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
}
// the loop routine runs over and over again forever:
void loop() {
if (radio.available()) {
byte bufByte[3];
bool last;
last = radio.read(&bufByte, sizeof(pingout));
for(int i=0; i<3; i++) {
char buffer[4];
sprintf(buffer, "0x%02x ",bufByte[i]);
Serial.print(buffer);
}
Serial.println();
radio.stopListening();
radio.write(&bufByte, sizeof(bufByte));
radio.startListening();
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment