I recently use the code liked above for my macro keyboard and it works perfectly fine, however I still have a few more free keys on it. I don't know too much about coding & I like to ask if some of you all can figure out how to increase the number of possibilities for these extra keys, a good example I think will be to create combinations with CTRL or ALT + F13...24.
Let me know if I did not explain myself right.
Thanks in ahead.
/* Code for f13-f24 keys working
Really basic setup for individual pins per button.
Circuit; push button connected between pins and ground.
Not using delay. 30 ms debounce
Based on the code by Fexduino from - http://forum.arduino.cc/index.php?topic=324554.0
*/
#include "Keyboard.h" // v1.0.2 or later of the keyboard library required
/* const int buttonPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
Due pins above, remove comment out if using Due
pro micro (leonardo to the IDE board list) below, comment out if using a Due
*/
const byte buttonPins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 14, 15}; // - continuing in order 18, 19, 20, 21, should you want to add more.
const int buttonKeys[] = {KEY_LALT, KEY_F13, KEY_F14, KEY_F15, KEY_F16, KEY_F17, KEY_F18, KEY_F19, KEY_F20, KEY_F21, KEY_F22, KEY_F23, KEY_F24};
bool buttonStates[13] = { false};
const int pollRate = 30; // change this figure if the debounce number needs to be higher or lower
unsigned long m = 0;
void setup() {
for (byte i = 0; i < sizeof(buttonPins); i++)
pinMode(buttonPins[i], INPUT_PULLUP);
m = millis();
}
void loop() {
if (millis() - m > pollRate) {
m += pollRate;
for (byte i = 0; i < sizeof(buttonPins); i++) {
bool state = digitalRead(buttonPins[i]);
if (state == LOW && !buttonStates[i]) {
buttonStates[i] = true;
Keyboard.press(buttonKeys[i]);
}
else if (state == HIGH && buttonStates[i]) {
buttonStates[i] = false;
Keyboard.release(buttonKeys[i]);
}
}
}
}