add preview and RGB

master
adb 4 years ago
parent e39aac0769
commit 24a6568d66

@ -11,10 +11,21 @@ IPAddress ip(192, 168, 178, 30);
//IP of the ATEM switcher //IP of the ATEM switcher
ATEM AtemSwitcher(IPAddress(192, 168, 178, 20), 56417); ATEM AtemSwitcher(IPAddress(192, 168, 178, 20), 56417);
//tally LEDs //program
const int tallyLED[] = {2,3,4,5}; boolean programStat[4] = {1,1,1,1};
const int tallyLEDlength = 4; # define programStatLength 4
boolean tallyLEDstat[4];
//preview
boolean previewStat[4] = {1,1,1,1};
# define previewStatLength 4
//program LEDs
const int programLED[] = {2,4};
# define programLEDlength 2
//preview LEDs
const int previewLED[] = {3,5};
# define previewLEDlength 2
//init NRF //init NRF
RF24 radio (7, 8); RF24 radio (7, 8);
@ -27,11 +38,15 @@ unsigned long previousTime = 0;
const long intervalTime = 1000; const long intervalTime = 1000;
void setup(){ void setup(){
for (int i=0; i < tallyLEDlength; i++){ for (int i=0; i < programLEDlength; i++){
pinMode(tallyLED[i], OUTPUT); pinMode(programLED[i], OUTPUT);
digitalWrite(tallyLED[i], LOW); digitalWrite(programLED[i], HIGH);
} }
for (int i=0; i < previewLEDlength; i++){
pinMode(previewLED[i], OUTPUT);
digitalWrite(previewLED[i], HIGH);
}
//start Ethernet //start Ethernet
Ethernet.begin(mac,ip); Ethernet.begin(mac,ip);
@ -41,7 +56,7 @@ void setup(){
//connect to the switcher //connect to the switcher
Serial.println("connect to ATEM"); Serial.println("connect to ATEM");
AtemSwitcher.serialOutput(true); AtemSwitcher.serialOutput(false);
AtemSwitcher.connect(); AtemSwitcher.connect();
//start NRF //start NRF
@ -66,15 +81,22 @@ void loop(){
if (dataChanged() || currentTime - previousTime >= intervalTime){ if (dataChanged() || currentTime - previousTime >= intervalTime){
sendNRF(); sendNRF();
previousTime = currentTime; previousTime = currentTime;
delay(20);
} }
} }
void sendNRF(){ void sendNRF(){
for (int i=0; i < tallyLEDlength; i++) { //program
datasend = (datasend << 1) + tallyLEDstat[i]; for (int i=0; i < programStatLength; i++) {
datasend = (datasend << 1) + programStat[i];
}
datasend = datasend << (8 - programStatLength);
//preview
for (int i=0; i < programStatLength; i++) {
datasend = (datasend << 1) + previewStat[i];
} }
datasend = datasend << (8 - tallyLEDlength); datasend = datasend << (8 - previewStatLength);
datasend = (datasend << 8) + getChecksum(datasend & 0xFF); //datasend = (datasend << 8) + getChecksum(datasend & 0xFF);
Serial.print(" datasend: "); Serial.print(" datasend: ");
Serial.println(datasend, BIN); Serial.println(datasend, BIN);
@ -83,11 +105,17 @@ void sendNRF(){
boolean dataChanged(){ boolean dataChanged(){
boolean changed = false; boolean changed = false;
//Serial.println("tally: "); for (int i=0; i < programStatLength; i++){
for (int i=0; i < tallyLEDlength; i++){ if (AtemSwitcher.getProgramTally(i+1) != programStat[i]){
if (AtemSwitcher.getProgramTally(i+1) != tallyLEDstat[i]){ programStat[i] = AtemSwitcher.getProgramTally(i+1);
tallyLEDstat[i] = AtemSwitcher.getProgramTally(i+1); if(programLEDlength > i)digitalWrite(programLED[i], programStat[i]);
digitalWrite(tallyLED[i], tallyLEDstat[i]); changed = true;
}
}
for (int i=0; i < previewStatLength; i++){
if (AtemSwitcher.getPreviewTally(i+1) != previewStat[i]){
previewStat[i] = AtemSwitcher.getPreviewTally(i+1);
if(previewLEDlength > i)digitalWrite(previewLED[i], previewStat[i]);
changed = true; changed = true;
} }
} }

@ -2,9 +2,9 @@
#include <nRF24L01.h> #include <nRF24L01.h>
//tally LEDs //tally LEDs
const int tallyLED[] = {2,3,4,5}; const int tallyLED[] = {2,4};
const int tallyLEDlength = 4; const int tallyLEDlength = 2;
boolean tallyLEDstat[4]; boolean tallyLEDstat[2];
# define errorLED 6 # define errorLED 6
@ -26,6 +26,12 @@ void setup(){
pinMode(errorLED, OUTPUT); pinMode(errorLED, OUTPUT);
digitalWrite(errorLED, HIGH); digitalWrite(errorLED, HIGH);
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
//start Serial //start Serial
Serial.begin(9600); Serial.begin(9600);
Serial.println("start serial"); Serial.println("start serial");
@ -34,7 +40,7 @@ void setup(){
Serial.println("start NRF"); Serial.println("start NRF");
radio.begin(); radio.begin();
radio.openReadingPipe(0, address); radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_LOW); radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate(RF24_1MBPS); radio.setDataRate(RF24_1MBPS);
radio.setAutoAck(false); radio.setAutoAck(false);
radio.disableCRC(); radio.disableCRC();

@ -0,0 +1,83 @@
#include <RF24.h>
#include <nRF24L01.h>
//tally RGB LED
const int tallyLED[] = {3,5,6}; //RGB
const int tallyLEDlength = 3;
boolean tallyLEDstat[3];
# define RGBground 4
# define channel 1
//init NRF
RF24 radio (7, 8);
const uint16_t address = 0xADB5;
uint16_t datareceive;
//define min interval to show error
unsigned long currentTime = millis();
unsigned long previousTime = 0;
const long errorTime = 3000;
void setup(){
for (int i=0; i < tallyLEDlength; i++){
pinMode(tallyLED[i], OUTPUT);
digitalWrite(tallyLED[i], LOW);
}
pinMode(RGBground, OUTPUT);
digitalWrite(RGBground, LOW);
//start Serial
Serial.begin(9600);
Serial.println("start serial");
//start NRF
Serial.println("start NRF");
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_HIGH);
radio.setDataRate(RF24_1MBPS);
radio.setAutoAck(false);
radio.disableCRC();
radio.startListening();
delay(20);
}
void loop(){
while (!updateLoop());
radio.read(&datareceive, sizeof(datareceive));
Serial.print("data: ");
Serial.println(datareceive, BIN);
if ((datareceive >> 15 - channel) & 1 == 1) setRGB(100,0,0);
else if ((datareceive >> 7 - channel) & 1 == 1) setRGB(0,30,0);
else setRGB(0,0,0);
}
boolean updateLoop(){
currentTime = millis();
if (radio.available()){
Serial.println("new package");
previousTime = currentTime;
return true;
}
else if (currentTime - previousTime >= errorTime){
Serial.println("timeout");
setRGB(0,0,50);
}
return false;
}
byte getChecksum(byte data){
byte checksum = 0;
for (int i=8; i<8; i++) checksum += (data >> i) & 1;
return checksum;
}
void setRGB(int r, int g, int b){
analogWrite(tallyLED[0], r);
analogWrite(tallyLED[1], g);
analogWrite(tallyLED[2], b);
}
Loading…
Cancel
Save