Hello,
I have a working sketch c/ Henny from the Vmix forums. It allows some video production software to be controlled via it's API over ethernet. The sketch is below.
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,1,85); // numeric IP for Google (no DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,202);
// pin button:
const int button2Pin = A1; // the number of the pushbutton pin
const int button3Pin = A2;
const int button4Pin = A3;
const int button5Pin = A4;
// variables will change:
int button2State = 0;
int button2StateOld = 0; // variable for reading the pushbutton status
int button3State = 0;
int button3StateOld = 0; // variable for reading the pushbutton status
int button4State = 0;
int button4StateOld = 0; // variable for reading the pushbutton status
int button5State = 0;
int button5StateOld = 0; // variable for reading the pushbutton status
int led = 9;
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
// initialize the pushbutton pin as an input:
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
pinMode(button4Pin, INPUT);
pinMode(button5Pin, INPUT);
pinMode(led, OUTPUT);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
digitalWrite(led, HIGH);
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop ()
{
loop1 ();
loop2 ();
loop3 ();
loop4 ();
}
void loop1 ()
{
button2StateOld=button2State;
button2State = digitalRead(button2Pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button2State != button2StateOld) {
if (button2State == HIGH){
Serial.println("Button1");
client.connect(server, 8088);
client.println("POST /API/?Function=PreviewInput&Input=1");
client.println();
client.stop();
}
}
}
void loop2 ()
{
button3StateOld=button3State;
button3State = digitalRead(button3Pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button3State != button3StateOld) {
if (button3State == HIGH){
Serial.println("Button2");
client.connect(server, 8088)
;
client.println("POST /API/?Function=PreviewInput&Input=2");
client.println();
client.stop();
}
}
}
void loop3 ()
{
button4StateOld=button4State;
button4State = digitalRead(button4Pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button4State != button4StateOld) {
if (button4State == HIGH){
Serial.println("Button3");
client.connect(server, 8088);
client.println("POST /API/?Function=PreviewInput&Input=3");
client.println();
client.stop();
}
}
}
void loop4 ()
{
button5StateOld=button5State;
button5State = digitalRead(button5Pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button5State != button5StateOld) {
if (button5State == HIGH){
Serial.println("Button4");
client.connect(server, 8088)
;
client.println("POST /API/?Function=cut");
client.println();
client.stop();
}
}
}
I want to connect a device to the arduino which provides open collector outputs ,but it does so in binary format.
I tried to combine two pins together like the snippet below and had no luck. Do I want to do something with an AND function, or is there another way to convert and store binary to (decimal?)
Thank you!
David
void loop1 ()
{
button2StateOld=button2State;
button2State = digitalRead(button2Pin);
button3StateOld=button3State;
button3State = digitalRead(button3Pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button2State != button2StateOld) {
if (button2State == HIGH){
if (button3State != button3StateOld) {
if (button3State == HIGH){
Serial.println("Button1and2");
client.connect(server, 8088);
client.println("POST /API/?Function=PreviewInput&Input=1");
client.println();
client.stop();
}
}
}
}
}