Here is the code so far. I am getting errors with the radio.write line. Suggestions are appreciated. I think that part of the problem is that I have cobbled together code from various places.
For the base unit:
/*Tricaster Transmit
- This sketch utilizes nrf24 transceivers to send a signal
- from the base station based on which camera is currently
- selected by the switcher.
*/
#include <SPI.h>
#include "RF24.h"
RF24 radio(9,10);
// Declare global variables
const uint64_t pipe = 0xE8E8F0F0E1LL;
int CAM1 = 2;
int CAM2 = 3;
int CAM3 = 4;
int CAM4 = 5;
int CAM5 = 6;
int CAM6 = 7;
int CAM7 = 14;
int CAM8 = 15;
int LEDR = 16;
int LEDG = 17;
int LEDY = 18;
int TRCSTR = 8;
int Number;
// Pin 9 ==> CE
// Pin 10 ==> CS(N)
// Pin 11 ==> MOSI
// Pin 12 ==> MISO
// Pin 13 ==> SCK
void setup(void){
//establish pin input and output
pinMode(CAM1, INPUT);
pinMode(CAM2, INPUT);
pinMode(CAM3, INPUT);
pinMode(CAM4, INPUT);
pinMode(CAM5, INPUT);
pinMode(CAM6, INPUT);
pinMode(CAM7, INPUT);
pinMode(CAM8, INPUT);
pinMode(TRCSTR, INPUT);
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDY, OUTPUT);
}
void loop(void){
// Begin serial communication
Serial.begin(9600);
radio.begin();
// the following statements improve transmission range
radio.setPayloadSize(1); // setting the payload size to the needed value
radio.setDataRate(RF24_250KBPS); // reducing bandwidth
radio.openWritingPipe(pipe);
// Show green LED if tricaster is plugged in and operating
// or show yellow LED if not
if(digitalRead(TRCSTR==HIGH)){
digitalWrite(LEDG, HIGH);
digitalWrite(LEDY, LOW);
}
else{
digitalWrite(LEDG,LOW);
digitalWrite(LEDY,HIGH);
}
// Determine which camera is selected and set variable cameraSelected to that selection
unsigned int cameraSelected = 0;
if (digitalRead(CAM1) == HIGH){
cameraSelected = 1;}
else if (digitalRead(CAM2) == HIGH){
cameraSelected = 2;}
else if (digitalRead(CAM3) == HIGH){
cameraSelected = 3;}
else if (digitalRead(CAM4) == HIGH){
cameraSelected = 4;}
else if (digitalRead(CAM5) == HIGH){
cameraSelected = 5;}
else if (digitalRead(CAM6) == HIGH){
cameraSelected = 6;}
else if (digitalRead(CAM7) == HIGH){
cameraSelected = 7;}
else if (digitalRead(CAM8) == HIGH){
cameraSelected = 8;}
else {cameraSelected = 0;
}
// Broadcast camera number to all receivers
radio.write (cameraSelected,1);
Serial.print (cameraSelected,1);
}
For the receiver:
/*Tricaster Receive
- This sketch utilizes nrf24 transceivers to recieve a signal
- from the base station and determine if this camera is currently
- selected by the switcher.
*/
#include <SPI.h>
#include "RF24.h"
RF24 radio(9,10);
// Assign Global Variables
int cameraSelected;
int Number;
const uint64_t pipe = 0xE8E8F0F0E1LL;
int DIP1 = 2;
int DIP2 = 3;
int DIP3 = 4;
int DIP4 = 5;
int DIP5 = 6;
int DIP6 = 7;
int DIP7 = 14;
int DIP8 = 15;
int LEDR = 16;
int LEDG = 17;
int LEDY = 18;
// Pin 9 ==> CE
// Pin 10 ==> CS(N)
// Pin 11 ==> MOSI
// Pin 12 ==> MISO
// Pin 13 ==> SCK
void setup(void){
// Determine which Receiver number from dip switch (1-8)
pinMode(DIP1, INPUT);
pinMode(DIP2, INPUT);
pinMode(DIP3, INPUT);
pinMode(DIP4, INPUT);
pinMode(DIP5, INPUT);
pinMode(DIP6, INPUT);
pinMode(DIP7, INPUT);
pinMode(DIP8, INPUT);
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDY, OUTPUT);
//This section Identifies receiver # that is
//attached to the cameras.
if (digitalRead(DIP1 == HIGH)){
Number=1;
}
else if (digitalRead(DIP2==HIGH)){
Number=2;
}
else if (digitalRead(DIP3==HIGH)){
Number=3;
}
else if (digitalRead(DIP4==HIGH)){
Number=4;
}
else if (digitalRead(DIP5==HIGH)){
Number=5;
}
else if (digitalRead(DIP6==HIGH)){
Number=6;
}
else if (digitalRead(DIP7==HIGH)){
Number=7;
}
else if (digitalRead(DIP8==HIGH)){
Number=8;
}
else {
Number = 0; // This ensures no error if no dip is selected
}
// Start Communications
Serial.begin(9600);
radio.begin();
// the following statements improve transmission range
radio.setPayloadSize(1); // setting the payload size to the needed value
radio.setDataRate(RF24_250KBPS); // reducing bandwidth
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop(void){
// Turns on green receive LED if the radio is available and
// yellow LED (radio off) if available
if (radio.available()){
digitalWrite(LEDG, HIGH);
digitalWrite(LEDY, LOW);
bool done = false;
// The following routine will read cameraSelected number from base
while (!done){
done = radio.read(cameraSelected,1);
Serial.println(cameraSelected);
}
// If the cameraSelected number matches number from base the red LED will light
// Otherwise the red LED will be turned off
if (cameraSelected == Number){
digitalWrite(LEDR, HIGH);
delay(10);
}
else {digitalWrite(LEDR, LOW);
}
delay(10);
}
// If radio is not available yellow LED on and Green LED off
else{Serial.println("No radio available");{
digitalWrite(LEDY,HIGH); //turns on yellow “no receive” light
digitalWrite(LEDG,LOW);}} //turns off green light
}
Again, thanks for suggestions