Arnov Sharma
Published © MIT

MACROPAD Pi

A three button Macropad powered by Raspberry Pi PICO 2

BeginnerFull instructions provided1 hour260
MACROPAD Pi

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1
NextPCB  Custom PCB Board
NextPCB Custom PCB Board
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fusion
Autodesk Fusion

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

cad file

Schematics

SCH

Code

code

C/C++
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keyboard.h>

// Pin Definitions
#define BUTTON_COPY   0
#define BUTTON_PASTE  1
#define BUTTON_DELETE 2

// OLED Display Config
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// State Tracking
unsigned long lastActionTime = 0;
bool showingCommand = false;

void setup() {
  pinMode(BUTTON_COPY, INPUT_PULLUP);
  pinMode(BUTTON_PASTE, INPUT_PULLUP);
  pinMode(BUTTON_DELETE, INPUT_PULLUP);

  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.display();

  Keyboard.begin();
  showIdle(); // Display "MACROPAD" at startup
}

void loop() {
  if (digitalRead(BUTTON_COPY) == LOW) {
    showCommand("Copy");
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('c');
    delay(100);
    Keyboard.releaseAll();
    lastActionTime = millis();
    showingCommand = true;
  }
  else if (digitalRead(BUTTON_PASTE) == LOW) {
    showCommand("Paste");
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('v');
    delay(100);
    Keyboard.releaseAll();
    lastActionTime = millis();
    showingCommand = true;
  }
  else if (digitalRead(BUTTON_DELETE) == LOW) {
    showCommand("Delete");
    Keyboard.press(KEY_DELETE);
    delay(100);
    Keyboard.releaseAll();
    lastActionTime = millis();
    showingCommand = true;
  }

  // Check if 5 seconds have passed since last action
  if (showingCommand && millis() - lastActionTime > 5000) {
    showIdle();
    showingCommand = false;
  }

  delay(100); // Loop throttle + debounce
}

void showCommand(String command) {
  display.clearDisplay();
  display.setTextSize(2);
  int16_t x = (SCREEN_WIDTH - command.length() * 12) / 2;
  display.setCursor(max(0, x), 20);
  display.println(command);
  display.display();
}

void showIdle() {
  display.clearDisplay();
  display.setTextSize(2);
  display.setCursor(20, 20);
  display.println("MACROPAD");
  display.display();
}

Credits

Arnov Sharma
345 projects • 353 followers
I'm Arnov. I build, design, and experiment with tech—3D printing, PCB design, and retro consoles are my jam.

Comments