Created
September 8, 2019 10:47
-
-
Save raek/b3b8cdfda4ad632d40b8b63b1e6b5e8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Keyboard.h" | |
void setup() { | |
pinMode(6, INPUT_PULLUP); | |
pinMode(13, OUTPUT); | |
Keyboard.begin(); | |
} | |
void loop() { | |
waitForStart(); | |
doMacro(); | |
} | |
void waitForStart() | |
{ | |
while (1) { | |
if (digitalRead(6) == LOW) { | |
digitalWrite(13, HIGH); | |
delay(1000); | |
return; | |
} | |
} | |
} | |
int keys[4] = { | |
KEY_RIGHT_ARROW, | |
KEY_DOWN_ARROW, | |
KEY_LEFT_ARROW, | |
KEY_UP_ARROW, | |
}; | |
void doMacro() | |
{ | |
int time = 0; | |
int key = 0; | |
while (1) { | |
while (digitalRead(6) == LOW) { | |
Keyboard.releaseAll(); | |
digitalWrite(13, LOW); | |
delay(1000); | |
return; | |
} | |
if (time == 0) { | |
Keyboard.press('1'); | |
} else if (time == 100) { | |
Keyboard.releaseAll(); | |
} else if (time == 4000) { | |
Keyboard.press(keys[key]); | |
} else if (time == 4100) { | |
Keyboard.releaseAll(); | |
} else if (time == 4200) { | |
Keyboard.press(keys[key]); | |
} else if (time == 4300) { | |
Keyboard.releaseAll(); | |
} else if (time == 4400) { | |
Keyboard.press(keys[key]); | |
} else if (time == 4500) { | |
Keyboard.releaseAll(); | |
} | |
delay(100); | |
time += 100; | |
if (time == 5000) { | |
time = 0; | |
key++; | |
key %= 4; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment