Hey, Im brand new to arduino and coding in general, and I was able to pull this code together, based off of a sample code for a similar macropad, for a 12 button macropad.
#include <Keyboard.h>
#include <Encoder.h>
Encoder RotaryEncoderA(14, 15);
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', '4'},
{'5', '6', '7', '8'},
{'9', '0', 'A', 'B'},
};
int modePushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
long positionEncoderA = -999;
const int ModeButton = A0;
const int Mode1= A2;
const int Mode2= A3;
byte rowPins[ROWS] = {4, 5, A3 };
byte colPins[COLS] = {6, 7, 8, 9 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
pinMode(ModeButton, INPUT_PULLUP);
Serial.begin(9600);
pinMode(Mode1,OUTPUT); digitalWrite(Mode1,LOW);
pinMode(Mode2,OUTPUT); digitalWrite(Mode2,LOW);
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
char key = keypad.getKey();
Serial.println(key);
digitalWrite(Mode1,LOW); digitalWrite(Mode2,LOW);
if (key) {
Serial.println(key);
switch (key) {
case '9':
Keyboard.press(KEY_LEFT_GUI);
Keyboard.print('d');
break;
case '0':
Keyboard.press(KEY_LEFT_GUI);
Keyboard.print('d');
break;
case 'A':
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F4);
break;
case 'B':
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print('a');
break;
case '5':
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print('z');
break;
case '6':
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.print('z');
break;
case '7':
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_TAB);
break;
case '8':
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_DELETE);
break;
case '1':
Keyboard.press(0x7F);
break;
case '2':
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print('c');
break;
case '3':
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print('x');
break;
case '4':
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print('v');
break;
}
delay(100); Keyboard.releaseAll();
}
}
The code uploads to the Pro micro no problem, however, when I press the keyboard switches, nothing happens.
Any help would be appreciated!