Skip to content

Instantly share code, notes, and snippets.

@aarontwf
Last active November 22, 2018 21:48
Show Gist options
  • Save aarontwf/753bc5c0cb4cd0a8da77e115eb6da375 to your computer and use it in GitHub Desktop.
Save aarontwf/753bc5c0cb4cd0a8da77e115eb6da375 to your computer and use it in GitHub Desktop.
#include <Ethernet2.h>
#include <SPI.h>
#include <SkaarhojPgmspace.h>
// MAC address and IP address for this *particular* Arduino / Ethernet Shield!
// The MAC address is printed on a label on the shield or on the back of your device
// The IP address should be an available address you choose on your subnet where the switcher is also present
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x0B, 0x68 }; // <= SETUP! MAC address of the Arduino
IPAddress clientIp(192, 168, 10, 99); // <= SETUP! IP address of the Arduino
IPAddress switcherIp(192, 168, 10, 240); // <= SETUP! IP address of the ATEM Switcher
// Include ATEMbase library and make an instance:
// The port number is chosen randomly among high numbers.
#include <ATEMbase.h>
#include <ATEMstd.h>
ATEMstd AtemSwitcher;
#include <LedButton.h>
const uint8_t NUM_PREVIEW_BUTTONS = 8;
LedButton previewButtons[NUM_PREVIEW_BUTTONS] = {
LedButton(22, 23),
LedButton(24, 25),
LedButton(26, 27),
LedButton(28, 29),
LedButton(30, 31),
LedButton(32, 33),
LedButton(34, 35),
LedButton(36, 37)
};
LedButton autoButton(40, 41);
LedButton cutButton(42, 43);
LedButton ftbButton(44, 45);
LedButton dsk1Button(46, 47);
LedButton dsk2Button(48, 49);
// the setup function runs once when you press reset or power the board
void setup() {
randomSeed(analogRead(5)); // For random port selection
// Start the Ethernet, Serial (debugging) and UDP:
Ethernet.begin(mac, clientIp);
Serial.begin(115200);
Serial.print("\n- - - - - - - -\nSerial Started\n");
// Setup Buttons
for (uint8_t i = 0; i < NUM_PREVIEW_BUTTONS; i++) {
previewButtons[i].setup();
}
autoButton.setup();
cutButton.setup();
ftbButton.setup();
dsk1Button.setup();
dsk2Button.setup();
// Initialize a connection to the switcher:
AtemSwitcher.begin(switcherIp);
AtemSwitcher.serialOutput(0x80);
AtemSwitcher.connect();
}
bool atemOnline = false;
void loop() {
// Check for packets, respond to them etc. Keeping the connection alive!
// VERY important that this function is called all the time - otherwise connection might be lost because packets from the switcher is
// overlooked and not responded to.
AtemSwitcher.runLoop();
// If the switcher has been initialized, check for button presses as reflect status of switcher in button lights:
if (AtemSwitcher.hasInitialized()) {
if (!atemOnline) {
atemOnline = true;
Serial.print("Turning on buttons\n");
}
updateButtons();
setButtonColors();
commandDispatch();
} else {
if (atemOnline) {
atemOnline = false;
Serial.print("Turning off buttons light\n");
}
connecting();
}
}
void connecting() {
previewButtons[3].read();
if ((unsigned long)millis() & B10000000) {
dsk1Button.ledOn();
dsk2Button.ledOff();
for (uint8_t i = 0; i < NUM_PREVIEW_BUTTONS; i++) {
if (i % 2 == 0) {
previewButtons[i].ledOn();
} else {
previewButtons[i].ledOff();
}
}
} else {
dsk1Button.ledOff();
dsk2Button.ledOn();
for (uint8_t i = 0; i < NUM_PREVIEW_BUTTONS; i++) {
if (i % 2 == 0) {
previewButtons[i].ledOff();
} else {
previewButtons[i].ledOn();
}
}
}
}
void updateButtons() {
for (uint8_t i = 0; i < NUM_PREVIEW_BUTTONS; i++) {
previewButtons[i].read();
}
autoButton.read();
cutButton.read();
ftbButton.read();
dsk1Button.read();
dsk2Button.read();
}
/*************************
* Set button colors
*************************/
void setButtonColors() {
// Input select buttons:
for (uint8_t i = 0; i < NUM_PREVIEW_BUTTONS; i++) {
if (AtemSwitcher.getPreviewTally(i)) {
previewButtons[i].ledOn();
} else {
previewButtons[i].ledOff();
}
}
// Command buttons:
if (AtemSwitcher.getTransitionPosition() > 0) {
autoButton.ledOn();
} else {
autoButton.ledOff();
}
if (cutButton.isReleased()) {
cutButton.ledOff();
}
// Downstream Key Buttons:
if (AtemSwitcher.getDownstreamKeyerStatus(1)) {
dsk1Button.ledOn();
} else {
dsk1Button.ledOff();
}
if (AtemSwitcher.getDownstreamKeyerStatus(2)) {
dsk2Button.ledOn();
} else {
dsk2Button.ledOff();
}
if (AtemSwitcher.getFadeToBlackState()) {
if (AtemSwitcher.getFadeToBlackTime() > 0 && (AtemSwitcher.getFadeToBlackFrameCount() != AtemSwitcher.getFadeToBlackTime())) {
// Blinking if Fade To Black is executing:
if ((unsigned long)millis() & B10000000) {
ftbButton.ledOn();
} else {
ftbButton.ledOff();
}
} else {
ftbButton.ledOn();
}
} else {
ftbButton.ledOff();
}
}
/*************************
* Commands handling
*************************/
void commandDispatch() {
// Input select buttons:
for (uint8_t i = 0; i < NUM_PREVIEW_BUTTONS; i++) {
if (previewButtons[i].wasPressed()) {
AtemSwitcher.changePreviewInput(i + 1);
}
}
// The following detects if a button is pressed for either AUTO or CUT:
if (autoButton.wasPressed()) {
AtemSwitcher.doAuto();
}
if (cutButton.wasPressed()) {
cutButton.ledOn();
AtemSwitcher.doCut();
}
// FTB:
if (ftbButton.wasPressed()) {
AtemSwitcher.fadeToBlackActivate();
}
// Key
if (dsk1Button.wasPressed()) {
AtemSwitcher.changeDownstreamKeyOn(1, !AtemSwitcher.getDownstreamKeyerStatus(1));
}
if (dsk2Button.wasPressed()) {
AtemSwitcher.changeDownstreamKeyOn(2, !AtemSwitcher.getDownstreamKeyerStatus(2));
}
}
@ratanlivebd
Copy link

Hello sir , i need 8 preview button Led , 8 pgm with Led , what is the change , could you pless made the code for me ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment