#include #include #include #include #include //Ethernet byte mac[] = {0xAA, 0xDD, 0xBB, 0x10, 0x01, 0x01}; IPAddress ip(192, 168, 0, 20); //IP of the ATEM switcher 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(); unsigned long previousTime = 0; const long intervalTime = 1000; void setup(){ for (int i=0; i < tallyLEDlength; i++){ pinMode(tallyLED[i], OUTPUT); digitalWrite(tallyLED[i], LOW); } //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 packages AtemSwitcher.runLoop(); 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; }