Skip to content

Instantly share code, notes, and snippets.

@Eviltechie
Created July 4, 2017 21:55
Show Gist options
  • Save Eviltechie/24f2c1372c25f21e8a05fe9d71087530 to your computer and use it in GitHub Desktop.
Save Eviltechie/24f2c1372c25f21e8a05fe9d71087530 to your computer and use it in GitHub Desktop.
int led = 11; //Built in led on Teensy 2.0
int camera1 = 1;
int camera2 = 2;
int camera3 = 3;
int camera4 = 4;
int camera5 = 24;
int camera6 = 5;
int camera7 = 6;
int inputByte = -1;
void setup()
{
Serial.begin(9600); //Start our serial connection
pinMode(led, OUTPUT); //Declare our pins as outputs.
pinMode(camera1, OUTPUT);
pinMode(camera2, OUTPUT);
pinMode(camera3, OUTPUT);
pinMode(camera4, OUTPUT);
pinMode(camera5, OUTPUT);
pinMode(camera6, OUTPUT);
pinMode(camera7, OUTPUT);
}
void loop()
{
inputByte = Serial.read(); //Read the serial buffer
if(inputByte == -1) //If the byte was -1, there is no activity and we can turn every output off and blink the LED fast.
{
digitalWrite(camera1, LOW);
digitalWrite(camera2, LOW);
digitalWrite(camera3, LOW);
digitalWrite(camera4, LOW);
digitalWrite(camera5, LOW);
digitalWrite(camera6, LOW);
digitalWrite(camera7, LOW);
digitalWrite(led, HIGH);
delay(50);
digitalWrite(led, LOW);
delay(50);
}
else //Otherwise, there was some activity
{
if (inputByte == '0') //One corresponds to digital output zero on blue iris.
{
digitalWrite(camera1, HIGH); //We set the pin designated as camera 1 high to indicate a camera being triggered by blue iris.
digitalWrite(led, HIGH); //We also turn on the onboard led for debugging purposes.
}
else if (inputByte == '1') //One corresponds to output two, and so on.
{
digitalWrite(camera2, HIGH);
digitalWrite(led, HIGH);
}
else if (inputByte == '2')
{
digitalWrite(camera3, HIGH);
digitalWrite(led, HIGH);
}
else if (inputByte == '3')
{
digitalWrite(camera4, HIGH);
digitalWrite(led, HIGH);
}
else if (inputByte == '4')
{
digitalWrite(camera5, HIGH);
digitalWrite(led, HIGH);
}
else if (inputByte == '5')
{
digitalWrite(camera6, HIGH);
digitalWrite(led, HIGH);
}
else if (inputByte == '6')
{
digitalWrite(camera7, HIGH);
digitalWrite(led, HIGH);
}
delay(100); //Blue iris sends the triggers about every 100ms. This lets us delay approx. until the next trigger, resulting in a continuous output until triggers stop.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment