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)

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

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

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

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.

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

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

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

projects_led-leads1b.jpg

projects_led-leads2b.jpg

projects_led-leads3b.jpg

projects_led-leads4.jpg

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.jpg

projects_mount_led2.jpg

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. 

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.

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.

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.jpg

projects_velcro_mount.jpg

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.

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.

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

Program the Circuit Playground

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.

# 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)

import time

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

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(index):
    switch_led = leds[index]  # find the switch LED
    k = buttonkeys[index]  # get the corresp. keycode/str
    switch_led.value = True  # turn on LED
    kbd.press(k)  # send keycode


def releasebutton(index):
    switch_led = leds[index]  # find the switch LED
    k = buttonkeys[index]  # get the corresp. keycode/str
    switch_led.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 is False:  # button is pressed?
            buttonspressed[i] = True  # save pressed button
            # was button not pressed last time?
            if buttonspressedlast[i] is False:
                print("Pressed #%d" % i)
                pressbutton(i)
        else:
            buttonspressed[i] = False  # button was not pressed
            if buttonspressedlast[i] is 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)

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

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:

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:

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?

This guide was first published on Jan 23, 2018. It was last updated on Nov 21, 2018.