Maker.io main logo

Giant Mechanical Keyboard

2018-02-22 | By Adafruit Industries

License: See Original Project

Courtesy of Adafruit

Guide by Collin Cunningham

Overview

These giant-sized key switches from Kailh are massive! Many times the size of a traditional MX-style switch. Though intended as a novelty item, they’re fully functional and just begging to be put to good use. I picked up one of each type from Novelkeys - Blue (tactile click), Red (tactile bump), and Yellow (linear).

Giant Mechanical Keyboard

So, what can you do with a three-button keyboard? A giant control-alt-delete keyboard to kill programs with authority seems the most logical application …

What You'll Need

Basics:

For frame:

Build the Frame

projects_dowels

We'll need some sort of frame to support the switches during use. You can easily make one using square 3/4" x 36" dowels and wood glue.

Measure & Cut Dowels

projects_cutting_dowels

Use a hacksaw or bandsaw to cut your dowel into the following pieces:

  • 2 x 240mm length
  • 4 x 55.5mm length
  • 4 x 40mm length

Assemble

projects_gluing1

Apply wood glue to both ends of each 55.5mm piece of dowel and assemble them between the two longer 240mm pieces. Make sure to leave a 55.5m gap between each piece.

Clamp the frame together using clamps and allow the glue to cure - the glue I'm using sured within in an hour. Once the frame's glue has dried, remove the clamps and then move on to attaching the legs.

projects_gluing2

Apply glue to one end of each 30mm piece, secure them to each corner on the bottom side of the frame, clamp, and allow them to dry.

Mount Switches

projects_mount_switches

Place each switch in one of the frame's square slots. I used blue as Switch 1, yellow as Switch 2, and Red as Switch 3 and wrote some code to display corresponding colors on the Circuit Playground Express.

Wiring

projects_big_switch-wiring_diagram-999px

Each switch has four leads which need to be connected - two for the switch itself and two for its LED. Reference the above diagram and the list below for what connects to where.

Connections

  • Switch 1, Pin 1 → GND
  • Switch 1, Pin 2 → A7
  • LED 1, short lead → GND
  • LED 1, long lead → A6
  • Switch 2, Pin 1 → GND
  • Switch 2, Pin 2 → A5
  • LED 2, short lead → GND
  • LED 2, long lead → A4
  • Switch 3, Pin 1 → GND
  • Switch 3, Pin 2 → A3
  • LED 3, short lead → GND
  • LED 3, long lead → A2

Solder & Mount LEDs

solder-and-mount-leds

Bend the leads of each LED and solder and hook a piece of solid core wire to each lead. Use black wire on the shorter (negative) lead and colored wire on the longer (positive) lead. Solder the wire to each lead and use a piece of heat-shrink tubing on each one to prevent them from shorting together.

projects_mount_led1

Insert each LED into the LED slot on its respective switch. Use a small amount of hot glue to secure it in place.

Solder Switches

You can use solid core or stranded wire to make connections between the switches and the Circuit Playground. I used solid core to avoid having to twist and tin any wire leads.

projects_tin_leads

To make soldering our wires easier, apply a small amount of solder to each of the switch leads - just be sure not to heat the lead for more than a second or two.

projects_connect_grounds

Strip the ends of the black LED wires and wrap them around their respective switch's silver terminal. Cut and strip the ends from two additional pieces of black wire and use them to connect each of the switch's silver terminals as seen above.

projects_switch_lines

Cut and strip the ends from another piece of longer black wire and wrap it around switch 1's silver terminal. Cut three pieces of colored wire and wrap them around each switch's copper terminal.

Once all the pieces are in place, solder them securely to the terminals.

Solder Connections to the Circuit Playground Express

projects_velcro-4-3

Mount the Circuit Playground to the front of the frame using velcro or double-sided tape. This will keep it stable while we solder the final connections.

projects_CP-connections-wrapped

Take the black wire from switch 1's silver terminal and wrap its free end around the Circuit Playground's GND terminal. Connect the remaining switch and LED wires to the Circuit Playground using the connections list at the top of this page.

projects_CP-connections-soldered

Once you're sure all connections are correct, solder them to each terminal on the Circuit Playground.

Program the Circuit Playground

projects_finished2

If you haven't yet, visit the Circuit Playground Express introduction guide to learn about the CPX and how to install CircuitPython

Connect the Circuit Playground to your computer, copy the below code and save it as a file named code.py on your Circuit Playground's root directory.

Copy Code
# Big Control Alt Delete Board
# Code is written for the Circuit Playground Express board:
#   https://www.adafruit.com/product/3333
# Needs the NeoPixel module installed:
#   https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel
# Author: Collin Cunningham
# License: MIT License (https://opensource.org/licenses/MIT)

from digitalio import DigitalInOut, Direction, Pull
import board
import time
import neopixel
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2)
pixels.fill((0,0,0))
pixels.show()

# The pins connected to each switch/button
buttonpins = [board.A7, board.A5, board.A3]
# The pins connected to each LED
ledpins = [board.A6, board.A4, board.A2]

# our array of button & LED objects
buttons = []
leds = []

# The keycode sent for each switch/button, will be paired with a control key
buttonkeys = [Keycode.CONTROL, Keycode.ALT, Keycode.DELETE]
buttonspressed = [False, False, False]
buttonspressedlast = [False, False, False]

# the keyboard object!
kbd = Keyboard()
# we're americans :)
layout = KeyboardLayoutUS(kbd)

# make all button pin objects, make them inputs w/pullups
for pin in buttonpins:
    button = DigitalInOut(pin)
    button.direction = Direction.INPUT
    button.pull = Pull.UP
    buttons.append(button)

# make all LED objects, make them inputs w/pullups
for pin in ledpins:
    led = DigitalInOut(pin)
    led.direction = Direction.OUTPUT
    leds.append(led)

# set up the status LED
statusled = DigitalInOut(board.D13)
statusled.direction = Direction.OUTPUT

print("Waiting for button presses")

def pressbutton(i):
    l = leds[i]          # find the switch LED
    k = buttonkeys[i]    # get the corresp. keycode/str
    l.value = True       # turn on LED
    kbd.press(k)         # send keycode
   
def releasebutton(i):
    l = leds[i]          # find the switch LED
    k = buttonkeys[i]    # get the corresp. keycode/str
    l.value = False      # turn on LED
    kbd.release(k)       # send keycode
   
def lightneopixels():
    vals = [0, 0, 0]
    # if switch 0 pressed, show blue
    if buttonspressed[0]:
        vals[2] = 255
    # if switch 1 pressed, show yellow
    if buttonspressed[1]:
        vals[0] = 127
        vals[1] = 64
    # if switch 2 pressed, show red
    if buttonspressed[2]:
        vals[0] = 255
    # if all pressed, show white
    if buttonspressed[0] and buttonspressed[1] and buttonspressed[2]:
        vals = [255,255,255]
    # if 0 & 1 pressed, show green
    if buttonspressed[0] and buttonspressed[1] and not buttonspressed[2]:
        vals = [0,255,0]
    pixels.fill((vals[0],vals[1],vals[2]))
    pixels.show()
   

while True:
    # check each button
    for button in buttons:
        i = buttons.index(button)
        if button.value == False:    # button is pressed?
            buttonspressed[i] = True # save pressed button
            if buttonspressedlast[i] == False: # was button not pressed last time?
                print("Pressed #%d" % i)
                pressbutton(i)
        else:
            buttonspressed[i] = False # button was not pressed
            if buttonspressedlast[i] == True: # was button pressed last time?
                print("Released #%d" % i)
                releasebutton(i)
    lightneopixels()
    # save pressed buttons as pressed last
    buttonspressedlast = list(buttonspressed)
    time.sleep(0.01)

 

projects_giant-mechanical-keyboard-2keyspressed4

If everything worked correctly, pressing a switch should light its LED, change the color of the Circuit Playground's neopixels, and send a keyboard command out over USB to your computer. Additionally, pressing multiple switches simultaneously should mix each switch's color and display it on the Circuit Playground.

Use it

projects_giant-mechanical-keyboard

By default, the switches will send the following keystrokes when pressed:

  • Switch 1 = CONTROL
  • Switch 2 = ALT
  • Switch 3 = DELETE

Each switch's LED will light when pressed, its corresponding color will display on the Circuit Playground's built-in neopixel LEDs, and colors will mix when pressed simultaneously.

Customize it

You can easily change what keystrokes are sent from each switch by modifying the code. Check out the following line from the code we uploaded in the previous step:

Copy Code
buttonkeys = [Keycode.CONTROL, Keycode.ALT, Keycode.DELETE]

 

Change the above keycodes to whatever you like by finding your preferred keycode in the adafruit_hid.keycode reference.

For example: If you want to use the switches to open the Force Quit Applications window on a Mac (Command-Option-Escape), change the line to:

Copy Code
buttonkeys = [Keycode.GUI, Keycode.ALT, Keycode.ESCAPE]

 

Of course, since the switches are simple digital inputs on the Circuit Playground, you can use them as pretty much anything – sound triggers, game buzzers, robotics controller, etc.

Really - what electronics couldn't benefit from giant button input?

制造商零件编号 3333
CIRCUIT PLAYGROUND EXPRESS
Adafruit Industries LLC
¥203.09
Details
制造商零件编号 1311
HOOK-UP 22AWG SOLID - 6 X 25FT
Adafruit Industries LLC
¥133.82
Details
制造商零件编号 1008
TEST LEAD GATOR TO GATOR 15"
Adafruit Industries LLC
¥32.15
Details
制造商零件编号 AK67421-2
CBL USB2.0 A PLG-MCR B PLG 6.56'
Assmann WSW Components
¥54.46
Details
制造商零件编号 JIC-842
PLIERS ELECT LONG NOSE 6.75"
Jonard Tools
¥167.35
Details
制造商零件编号 VAOL-10GWY4
LED WHITE CLEAR T/H
Visual Communications Company - VCC
¥9.94
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum