Alex Wulff
Published © CC BY-NC-SA

Capacitive Touch Keyboard Extension with Leonardo

Extend the functionality of your current keyboard with custom capacitive touch keys.

EasyFull instructions provided2 hours4,669

Things used in this project

Hardware components

DFRobot Gravity Digital Capacitive Touch Sensor
×4
Arduino Leonardo
×1
Male-to-Male Jumper Wires
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Code

PrintChars

Arduino
#include <Keyboard.h>

void setup(){
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  Keyboard.begin();
}

void loop(){
  checkPress(2, 'd');
  checkPress(3, 'f');
  checkPress(4, 'g');
  checkPress(5, 'h');
}

void checkPress(int pin, char key) {
  if (digitalRead(pin)) {
    Keyboard.press(key);
  }

  else {
    Keyboard.release(key);
  }
}

Hotkeys

Arduino
#include <Keyboard.h>

const int delayValue = 100;
const char cmdKey = KEY_LEFT_GUI;

void setup(){
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  Keyboard.begin();
}

void loop(){
  if (digitalRead(2)) {
    Keyboard.press(cmdKey);
    Keyboard.press('c');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(2));
  }

  if (digitalRead(3)) {
    Keyboard.press(cmdKey);
    Keyboard.press('v');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(3));
  }

  if (digitalRead(4)) {
    Keyboard.press(cmdKey);
    Keyboard.press('n');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(4));
  }

  if (digitalRead(5)) {
    Keyboard.press(cmdKey);
    Keyboard.press('z');
    delay(delayValue);
    Keyboard.releaseAll();

    while(digitalRead(5));
  }
}

Credits

Alex Wulff

Alex Wulff

2 projects • 67 followers
I'm a 19-year-old maker from Upstate New York. I love Arduino, embedded systems, 3D printing, and iOS development. www.AlexWulff.com

Comments