/*
Forum: https://forum.arduino.cc/t/codeproblem-arduino-leonardo-als-tastatur/1160391/9
Wokwi: https://wokwi.com/projects/373704069599168513
*/
//#include <Keyboard.h>
#define Keyboard Serial
struct macroType {
byte Pin;
char Key;
};
macroType macro[] = {
{2, 'A'},
{3, 'B'},
{4, 'C'},
{5, 'D'},
{6, 'E'},
{7, 'F'},
{8, 'G'},
{9, 'H'}
};
constexpr byte NoOfMacros = sizeof(macro) / sizeof(macro[0]);
void setup() {
for (byte i = 0; i < NoOfMacros; i++) {
pinMode(macro[i].Pin, INPUT_PULLUP);
}
Keyboard.begin(115200);
}
void loop() {
for (byte i = 0; i < NoOfMacros; i++) {
if ( digitalRead(macro[i].Pin) == LOW) {
Keyboard.print(macro[i].Key);
delay(200);
}
}
}