Some single button controllers.
USB Button
Website $29.
Configurable through a PC only application to output keystrokes and light from an RGB led.
ARDUINO AND PUSH BUTTONS
If you want to make custom hardware you may want to use Arduino.
You can find all sort of switches/pushbuttons online, you can salvage them from old toys (they should all be easy to rewire) or make your own. It’s easy, check these instructables
Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that the pin reads as HIGH, or 1.
If you have no resistor when it’s closed it becomes be a short circuit and when it’s open it doesn’t have a defined/predictable value (it would float between 0 and 1 according to environmental condition).
Here’s how you make it.
Here I soldered the resistor on the wire so I can connect it directly to the Arduino without using a breadboard:
Upload this Arduino code and open the serial monitor:
void setup() { Serial.begin(9600); pinMode(2, INPUT); } void loop() { int sensorValue = digitalRead(2); Serial.println(sensorValue, DEC); } |
Pull up and pull down resistors
You’ll always see resistor connected to switches. That’s because when a circuit is open you’ll probably have parts of the circuit with floating value: the digital signal is inconsistently moving between +5V and 0V.
The solution is to use a “pull down” resistor between the switch and the ground to force a value to LOW when the circuit is open:
Or the opposite logic: forcing a HIGH value with a “pull up” resistor.
Note: The 100 ohm resistor in the scheme is to avoid a short circuit, that would happen only if you accidentally set the pin to output and set its value to LOW basically connecting +5V and ground, so it a cautionary measure.
BUT if you try Make a click counter like Luke Loeffler’s with a software output:
You’ll notice there are false positives. This is not a software (sketch) problem, but actually a mechanical problem.
Inside the little tactile switch is a small disc spring. When you push the button you squeeze the spring so that it makes contact with the two wire connections. When you release, the spring bounces back. This works great except that, well, the spring is springy. And that means that once in a while, when you press the button it bounces around a little in the switch, making and breaking contact a few times before settling.
Debounce and keystroke emulation
Debouncing is the software solution to this mechanical problem, see below.
Arduino Leonardo and Teensy can emulate keyboard and mouse, so we can communicate with anything that runs on the connected computer without using Firmata, OSC or serial communication.
This is the reference for the Keyboard functions.
//the character we want to type (SPACE) char myKey = ' '; //saving the state of the push button int buttonState = 0; void setup() { //button is on 2 pinMode(2, INPUT); //start emulating keyboard Keyboard.begin(); //start serial port for debug (open it with tools > serial monitor) Serial.begin(9600); } void loop() { //something changed if(buttonState != digitalRead(2)) { //wait delay(10); //read it again //still different if(buttonState != digitalRead(2)) { Serial.println("Stable state"); //then save on the buttonState variable buttonState = digitalRead(2); if(buttonState == HIGH) { Keyboard.press(myKey); Serial.println("button down"); } if(buttonState == LOW) { Keyboard.release(myKey); Serial.println("button up"); } } } } |
IPAC Board
Weapon of choice of the MAME/Emulator community. Easy to wire, includes debouncing and programming utility (which doesn’t work on new Mac OSX because fuck Apple).
Sketchy website ~$40
Wiring switches from an arcade-grade joystick. 32 digital inputs.
MaKey Makey
Turns any conductive and semiconductive materials into switches: Plants, Coins, Your Grandma, Silverware, Anything that is Wet, Most Foods, Cats and Dogs, Aluminum Foil, Rain…
Website $49