send NRF
This commit is contained in:
parent
8b974057e4
commit
c2a1510b16
@ -1,6 +1,8 @@
|
||||
#include <SPI.h>
|
||||
#include <UIPEthernet.h>
|
||||
#include <UIP_ATEM.h>
|
||||
#include <RF24.h>
|
||||
#include <nRF24L01.h>
|
||||
|
||||
//Ethernet
|
||||
byte mac[] = {0xAA, 0xDD, 0xBB, 0x10, 0x01, 0x01};
|
||||
@ -12,6 +14,12 @@ ATEM AtemSwitcher(IPAddress(192, 168, 0, 50), 56417);
|
||||
//tally LEDs
|
||||
const int tallyLED[] = {2,3};
|
||||
const int tallyLEDlength = 2;
|
||||
boolean tallyLEDstat[2];
|
||||
|
||||
//init NRF
|
||||
RF24 radio (7, 8);
|
||||
const uint16_t address = 0xADB5;
|
||||
uint16_t datasend = 0;
|
||||
|
||||
//define min interval to send data
|
||||
unsigned long currentTime = millis();
|
||||
@ -26,20 +34,62 @@ void setup(){
|
||||
|
||||
//start Ethernet
|
||||
Ethernet.begin(mac,ip);
|
||||
|
||||
|
||||
//start Serial
|
||||
Serial.begin(9600);
|
||||
|
||||
//connect to the switcher
|
||||
AtemSwitcher.serialOutput(true);
|
||||
AtemSwitcher.connect();
|
||||
|
||||
//start NRF
|
||||
radio.begin();
|
||||
radio.openWritingPipe(address);
|
||||
radio.setPALevel(RF24_PA_MIN);
|
||||
radio.setDataRate(RF24_1MBPS);
|
||||
//radio.disableDynamicPayloads();
|
||||
radio.setAutoAck(false);
|
||||
radio.disableCRC();
|
||||
radio.stopListening();
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
//check for new packets
|
||||
//check for new packages
|
||||
AtemSwitcher.runLoop();
|
||||
|
||||
//write tally LEDs
|
||||
for (int i=0; i < tallyLEDlength; i++){
|
||||
digitalWrite(tallyLED[i], !AtemSwitcher.getProgramTally(i+1));
|
||||
}
|
||||
previousTime = currentTime;
|
||||
currentTime = millis();
|
||||
|
||||
if (dataChanged() || currentTime - previousTime >= intervalTime)
|
||||
sendNRF();
|
||||
}
|
||||
|
||||
void sendNRF(){
|
||||
for (int i=0; i < tallyLEDlength; i++) {
|
||||
datasend = (datasend << 1) + tallyLEDstat[i];
|
||||
}
|
||||
datasend = datasend << (8 - tallyLEDlength);
|
||||
datasend = (datasend << 8) + getChecksum(datasend && 0xFF);
|
||||
|
||||
radio.writeFast(&datasend, sizeof(datasend));
|
||||
}
|
||||
|
||||
boolean dataChanged(){
|
||||
boolean changed = false;
|
||||
for (int i=0; i < tallyLEDlength; i++){
|
||||
if (AtemSwitcher.getProgramTally(i+1) == tallyLEDstat[i]){
|
||||
tallyLEDstat[i] = AtemSwitcher.getProgramTally(i+1);
|
||||
digitalWrite(tallyLED[i], !AtemSwitcher.getProgramTally(i+1));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
uint8_t getChecksum(uint8_t data){
|
||||
uint8_t checksum = 0;
|
||||
for (int i=8; i<8; i++) checksum += (data >> i) && 1;
|
||||
return checksum;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user