Skip to content

Instantly share code, notes, and snippets.

@beriberikix
Created August 2, 2017 22:45
Show Gist options
  • Save beriberikix/ecb77d8ea153d6fac1cf2f9c9d734c51 to your computer and use it in GitHub Desktop.
Save beriberikix/ecb77d8ea153d6fac1cf2f9c9d734c51 to your computer and use it in GitHub Desktop.
Code for atmega32u4-based OBS scene switcher
/**********************************************************************
/* Copyright 2017 Jonathan Beri
/*
/* Licensed under the Apache License, Version 2.0 (the "License");
/* you may not use this file except in compliance with the License.
/* You may obtain a copy of the License at
/*
/* http://www.apache.org/licenses/LICENSE-2.0
/*
/* Unless required by applicable law or agreed to in writing, software
/* distributed under the License is distributed on an "AS IS" BASIS,
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/* See the License for the specific language governing permissions and
/* limitations under the License.
#include "Keyboard.h"
// 32u4 has 5 interrupts [3,2,0,1,7]
const byte interruptPin0 = 3;
const byte interruptPin1 = 2;
const byte interruptPin2 = 0;
const byte interruptPin3 = 1;
const byte interruptPin4 = 7;
volatile byte command = 0;
void setup() {
// Pullup to set HIGH since ISR is called on LOW
pinMode(interruptPin0, INPUT_PULLUP);
pinMode(interruptPin1, INPUT_PULLUP);
pinMode(interruptPin2, INPUT_PULLUP);
pinMode(interruptPin3, INPUT_PULLUP);
pinMode(interruptPin4, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin0), ISR_setCommand1, LOW);
attachInterrupt(digitalPinToInterrupt(interruptPin1), ISR_setCommand2, LOW);
attachInterrupt(digitalPinToInterrupt(interruptPin2), ISR_setCommand3, LOW);
attachInterrupt(digitalPinToInterrupt(interruptPin3), ISR_setCommand4, LOW);
attachInterrupt(digitalPinToInterrupt(interruptPin4), ISR_setCommand5, LOW);
Keyboard.begin();
}
void loop() {
// Change keyboards commands here. See also https://www.arduino.cc/en/Reference/KeyboardModifiers
switch(command) {
case 1:// ⌘+1.
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('1');
Keyboard.releaseAll();
command = 0;
break;
case 2:
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('2');
Keyboard.releaseAll();
command = 0;
break;
case 3:
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('3');
Keyboard.releaseAll();
command = 0;
break;
case 4:
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('4');
Keyboard.releaseAll();
command = 0;
break;
case 5:
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('5');
Keyboard.releaseAll();
command = 0;
break;
default:
command = 0;
break;
}
}
void ISR_setCommand1() {
command = 1;
}
void ISR_setCommand2() {
command = 2;
}
void ISR_setCommand3() {
command = 3;
}
void ISR_setCommand4() {
command = 4;
}
void ISR_setCommand5() {
command = 5;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment