Skip to content

Instantly share code, notes, and snippets.

@luisdamed
Created March 17, 2023 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisdamed/b494c4503daf785cffc4dd06fd58e471 to your computer and use it in GitHub Desktop.
Save luisdamed/b494c4503daf785cffc4dd06fd58e471 to your computer and use it in GitHub Desktop.
A simple code to test the connections of a 3x3 macropad based on the Arduino Pro Micro
#include <Mouse.h>
#include <Keyboard.h>
// Defining each pin, with a unique name
#define KEY0 0
#define KEY1 1
#define KEY2 2
#define KEY3 3
#define KEY4 4
#define KEY5 5
#define KEY6 6
#define KEY7 7
#define KEY8 8
void setup() {
pinMode (KEY0, INPUT_PULLUP);
pinMode (KEY1, INPUT_PULLUP);
pinMode (KEY2, INPUT_PULLUP);
pinMode (KEY3, INPUT_PULLUP);
pinMode (KEY4, INPUT_PULLUP);
pinMode (KEY5, INPUT_PULLUP);
pinMode (KEY6, INPUT_PULLUP);
pinMode (KEY7, INPUT_PULLUP);
pinMode (KEY8, INPUT_PULLUP);
//starting the strip
Keyboard.begin();
Mouse.begin();
}
void loop() {
//key 0//
if (digitalRead(KEY0) == LOW)
{
Keyboard.press(KEY_LEFT_CTRL); //change the keyname in the parenthese to any from:https://www.arduino.cc/en/Reference/KeyboardModifiers, if you want multiple, duplicate this command//
Keyboard.print("c");
delay(100); //this sets a delay so the keybind doesnt spam, and only goes once per 100 milliseconds in this case//
}
if (digitalRead(KEY0) == HIGH)
{
Keyboard.releaseAll();
}
if (digitalRead(KEY1) == LOW)
{
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print("v"); //if you want a letter use this command, but dont capitalize unless you want a "SHIFT" click along with your letter(s)//
delay(100);
}
if (digitalRead(KEY1) == HIGH)
{
Keyboard.releaseAll();
}
if (digitalRead(KEY2) == LOW)
{
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print("0");
delay(100);
}
if (digitalRead(KEY2) == HIGH)
{
Keyboard.releaseAll();
}
if (digitalRead(KEY3) == LOW)
{
//Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print("3");
delay(100);
}
if (digitalRead(KEY3) == HIGH)
{
Keyboard.releaseAll();
}
if (digitalRead(KEY4) == LOW)
{
//Keyboard.press(KEY_LEFT_GUI);
Keyboard.print("4");
delay(100);
}
if (digitalRead(KEY4) == HIGH)
{
Keyboard.releaseAll();
}
//Top Right Button//
if (digitalRead(KEY5) == LOW)
{
//Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print("5");
delay(100);
}
if (digitalRead(KEY5) == HIGH)
{
Keyboard.releaseAll();
}
if (digitalRead(KEY6) == LOW)
{
//Keyboard.press(KEY_LEFT_ALT);
Keyboard.print("6");
delay(100);
}
if (digitalRead(KEY6) == HIGH)
{
Keyboard.releaseAll();
delay(100);
}
if (digitalRead(KEY7) == LOW)
{
//Keyboard.press(KEY_LEFT_CTRL);
Keyboard.print("7");
delay(100);
}
if (digitalRead(KEY7) == HIGH)
{
Keyboard.releaseAll();
}
if (digitalRead(KEY8) == LOW)
{
//Keyboard.press(KEY_CAPS_LOCK);
Keyboard.print("8");
delay(100);
}
if (digitalRead(KEY8) == HIGH)
{
Keyboard.releaseAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment