Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Toby's Low Cost Macro Keyboard
- */
- #ifndef USER_USB_RAM
- #error "Require USB RAM. Go Tools > USB Setting and pick the 2nd option in the dropdown list"
- #endif
- #include "src/userUsbHidMediaKeyboard/USBHIDMediaKeyboard.h"
- ////////////// HARDWARE CONFIG //////////
- //Mode LED
- #define LED_A 34
- #define LED_B 33
- //Mode switch
- #define SWITCH 14
- //Button (Mechnical, left to right)
- #define BTN_1 15
- #define BTN_2 16
- #define BTN_3 17
- #define BTN_4 11
- ///////////////// RUNTIME ///////////////
- //Current Mode
- bool modeA = true;
- //Previous button states
- bool bt1ActiveState = false;
- bool bt2ActiveState = false;
- bool bt3ActiveState = false;
- bool bt4ActiveState = false;
- //Current button states
- bool bt1Active = false;
- bool bt2Active = false;
- bool bt3Active = false;
- bool bt4Active = false;
- ////////////// Special Hotkeys //////////////////
- //When Button 2 is hold in mode A, activate volume Mode to
- //allow button 3 and 4 to change volume instead of prev / next song
- bool volMode = false;
- void setup() {
- USBInit();
- pinMode(SWITCH, INPUT);
- pinMode(LED_A, OUTPUT);
- pinMode(LED_B, OUTPUT);
- if (!digitalRead(SWITCH)){
- digitalWrite(LED_A, HIGH);
- digitalWrite(LED_B, LOW);
- }else{
- digitalWrite(LED_A, LOW);
- digitalWrite(LED_B, HIGH);
- }
- }
- void loop() {
- //Read the mode of the keyboard
- modeA = !digitalRead(SWITCH);
- //Read the button states, default PULL HIGH (aka LOW Activate)
- bt1Active = !digitalRead(BTN_1);
- bt2Active = !digitalRead(BTN_2);
- bt3Active = !digitalRead(BTN_3);
- bt4Active = !digitalRead(BTN_4);
- if (modeA == HIGH){
- //Mode A
- //Media Controller
- //Button 1: Play / Pause
- if (bt1ActiveState != bt1Active){
- bt1ActiveState = bt1Active;
- if (bt1Active){
- Consumer_press(MEDIA_PLAY_PAUSE);
- }else{
- Consumer_release(MEDIA_PLAY_PAUSE);
- }
- }
- //Button 2: Toggle Playlist / Volumn Control Mode
- if (bt2ActiveState != bt2Active){
- bt2ActiveState = bt2Active;
- if (bt2Active){
- volMode = true;
- }else{
- volMode = false;
- }
- }
- //Previous Song / Vol Down
- if (bt3ActiveState != bt3Active){
- bt3ActiveState = bt3Active;
- if (volMode){
- //Button 2 is held
- if (bt3Active){
- Consumer_press(MEDIA_VOLUME_DOWN);
- }else{
- Consumer_release(MEDIA_VOLUME_DOWN);
- }
- }else{
- //Default mode
- if (bt3Active){
- Consumer_press(MEDIA_PREV);
- }else{
- Consumer_release(MEDIA_PREV);
- }
- }
- }
- //Button 4: Next Song / Vol Up
- if (bt4ActiveState != bt4Active){
- bt4ActiveState = bt4Active;
- if (volMode){
- //Button 2 is held
- if (bt4Active){
- Consumer_press(MEDIA_VOLUME_UP);
- }else{
- Consumer_release(MEDIA_VOLUME_UP);
- }
- }else{
- //Default mode
- if (bt4Active){
- Consumer_press(MEDIA_NEXT);
- }else{
- Consumer_release(MEDIA_NEXT);
- }
- }
- }
- //Set the status LED
- digitalWrite(LED_A, HIGH);
- digitalWrite(LED_B, LOW);
- }else{
- //Mode B
- //For Adobe Premiere Pro CS6 hotkey
- //Button 1: Cut clip at cursor location
- if (bt1ActiveState != bt1Active){
- bt1ActiveState = bt1Active;
- if (bt1Active){
- //Ctrl + K = Cut
- Keyboard_press(KEY_LEFT_CTRL);
- delay(100);
- Keyboard_write('k');
- delay(100);
- Keyboard_release(KEY_LEFT_CTRL);
- }
- }
- //Button 2: Snap to next marker and cut
- if (bt2ActiveState != bt2Active){
- bt2ActiveState = bt2Active;
- if (bt2Active){
- //Shift + M = Next Marker
- Keyboard_press(KEY_LEFT_SHIFT);
- delay(100);
- Keyboard_write('m');
- delay(100);
- Keyboard_release(KEY_LEFT_SHIFT);
- delay(100);
- //Ctrl + K = Cut
- Keyboard_press(KEY_LEFT_CTRL);
- delay(100);
- Keyboard_write('k');
- delay(100);
- Keyboard_release(KEY_LEFT_CTRL);
- }
- }
- //Button 3: Cut and ripple delete (Require selecting the target clip before click)
- if (bt3ActiveState != bt3Active){
- bt3ActiveState = bt3Active;
- if (bt3Active){
- //Ctrl + K = Cut
- Keyboard_press(KEY_LEFT_CTRL);
- delay(100);
- Keyboard_write('k');
- delay(100);
- Keyboard_release(KEY_LEFT_CTRL);
- //UP = Move to front of the clip
- delay(100);
- Keyboard_press(KEY_UP_ARROW);
- delay(100);
- Keyboard_release(KEY_UP_ARROW);
- //Ripple Delete
- delay(100);
- Keyboard_press(KEY_LEFT_SHIFT);
- delay(100);
- Keyboard_press(KEY_DELETE);
- delay(100);
- Keyboard_release(KEY_DELETE);
- Keyboard_release(KEY_LEFT_SHIFT);
- }
- }
- //Button 4: Ripple Delete (Require selecting clip)
- if (bt4ActiveState != bt4Active){
- bt4ActiveState = bt4Active;
- if (bt4Active){
- //Shift + DEL = Ripple delete
- Keyboard_press(KEY_LEFT_SHIFT);
- delay(100);
- Keyboard_press(KEY_DELETE);
- delay(100);
- Keyboard_release(KEY_DELETE);
- Keyboard_release(KEY_LEFT_SHIFT);
- }
- }
- //Set the status LED
- digitalWrite(LED_A, LOW);
- digitalWrite(LED_B, HIGH);
- }
- delay(50); //naive debouncing
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement