-
Notifications
You must be signed in to change notification settings - Fork 7
/
tally-light-esp32-for-blackmagic-atem-switcher.ino
96 lines (70 loc) · 2.67 KB
/
tally-light-esp32-for-blackmagic-atem-switcher.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*****************
Tally light ESP32 for Blackmagic ATEM switcher
Version 2.0
A wireless (WiFi) tally light for Blackmagic Design
ATEM video switchers, based on the M5StickC ESP32 development
board and the Arduino IDE.
For more information, see:
https://oneguyoneblog.com/2020/06/13/tally-light-esp32-for-blackmagic-atem-switcher/
Based on the work of Kasper Skårhøj:
https://github.com/kasperskaarhoj/SKAARHOJ-Open-Engineering
******************/
#include <M5StickC.h>
#include <WiFi.h>
#include <SkaarhojPgmspace.h>
#include <ATEMbase.h>
#include <ATEMstd.h>
IPAddress clientIp(192, 168, 178, 170); // IP address of the ESP32
IPAddress switcherIp(192, 168, 178, 173); // IP address of the ATEM switcher
ATEMstd AtemSwitcher;
// http://www.barth-dev.de/online/rgb565-color-picker/
#define GRAY 0x0020 // 8 8 8
#define GREEN 0x0200 // 0 64 0
#define RED 0xF800 // 255 0 0
const char* ssid = "yournetwork";
const char* password = "yourpassword";
int cameraNumber = 4;
int ledPin = 10;
int PreviewTallyPrevious = 1;
int ProgramTallyPrevious = 1;
void setup() {
Serial.begin(9600);
// Start the Ethernet, Serial (debugging) and UDP:
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
// initialize the M5StickC object
M5.begin();
pinMode(ledPin, OUTPUT); // LED: 1 is on Program (Tally)
digitalWrite(ledPin, HIGH); // off
// Initialize a connection to the switcher:
AtemSwitcher.begin(switcherIp);
AtemSwitcher.serialOutput(0x80);
AtemSwitcher.connect();
}
void loop() {
// Check for packets, respond to them etc. Keeping the connection alive!
AtemSwitcher.runLoop();
int ProgramTally = AtemSwitcher.getProgramTally(cameraNumber);
int PreviewTally = AtemSwitcher.getPreviewTally(cameraNumber);
if ((ProgramTallyPrevious != ProgramTally) || (PreviewTallyPrevious != PreviewTally)) { // changed?
if ((ProgramTally && !PreviewTally) || (ProgramTally && PreviewTally) ) { // only program, or program AND preview
drawLabel(RED, BLACK, LOW);
} else if (PreviewTally && !ProgramTally) { // only preview
drawLabel(GREEN, BLACK, HIGH);
} else if (!PreviewTally || !ProgramTally) { // neither
drawLabel(BLACK, GRAY, HIGH);
}
}
ProgramTallyPrevious = ProgramTally;
PreviewTallyPrevious = PreviewTally;
}
void drawLabel(unsigned long int screenColor, unsigned long int labelColor, bool ledValue) {
digitalWrite(ledPin, ledValue);
M5.Lcd.fillScreen(screenColor);
M5.Lcd.setTextColor(labelColor, screenColor);
M5.Lcd.drawString(String(cameraNumber), 15, 40, 8);
}