Arnov Sharma
Published © MIT

PastePal

A simple two-button macropad for copy and paste commands, we have added a display that outputs the keypress.

BeginnerFull instructions provided1 hour4,914
PastePal

Things used in this project

Software apps and online services

Fusion
Autodesk Fusion

Hand tools and fabrication machines

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

Story

Read more

Custom parts and enclosures

Fusion360File

Schematics

SCH

Code

code

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET    -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const int buttonCopyPin = 1; // Pin for the copy button
const int buttonPastePin = 0; // Pin for the paste button

void setup() {
  // Initialize the OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.display();
  delay(2000);
  display.clearDisplay();

  // Initialize the buttons
  pinMode(buttonCopyPin, INPUT_PULLUP);
  pinMode(buttonPastePin, INPUT_PULLUP);

  // Initialize the Keyboard library
  Keyboard.begin();
}

void loop() {
  if (digitalRead(buttonCopyPin) == LOW) {
    display.clearDisplay();
    display.setTextSize(3);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 5);
    display.print("Copy");
    display.display();
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('c');
    delay(100);
    Keyboard.releaseAll();
    delay(500); // Debounce delay
  }

  if (digitalRead(buttonPastePin) == LOW) {
    display.clearDisplay();
    display.setTextSize(3);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 5);
    display.print("Paste");
    display.display();
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('v');
    delay(100);
    Keyboard.releaseAll();
    delay(500); // Debounce delay
  }
}

Credits

Arnov Sharma
333 projects • 339 followers
Just your average MAKER
Contact

Comments

Please log in or sign up to comment.