Game Controller – Lunar Lander

This week’s assignment is to make a game controller for Lunar Lander. My goal was to use materials I have on hand and not spend additional money. The scraps of conductive fabric in my toolbox reminded me of capacitive touch sensing and a project previous ITP students worked on called the Gesture-Sensing Tek-Tile:

I had the pleasure of talking to Renata last semester about it and she explained that it uses capacitive touch sensing with a break-out board that you can buy on Adafruit. I did some research and found that it can be done digitally (albeit less conveniently) by connecting each sensor to 2 pins, send and receive. The send pin, which can be shared by multiple sensors, must connect with a large-value resistor between 100K to 50M (I used 100K). I modified the Capacitive Sensor library example code below and was surprised to see ten digit values shoot up to 800+ with light taps.

When I transferred my set up from Arduino Uno over to Adafruit’s Feather M0, I was not able to receive data from any of my sensors. I then troubleshooted with an Arduino MKR1000 from the shop and it worked perfectly. The only difference I can discern is the feather can only supply up to 3.3V, which I’m assuming is the issue…

  

Code (I referenced a capacitive sensor Arduino piano instructable by Tyler Crumpton) :

#include <Keyboard.h>
#include <CapacitiveSensor.h>

#define COMMON_PIN 4 // The common ‘send’ pin for all keys
#define NUM_OF_SAMPLES 30 // Higher number when more delay but more consistent readings
#define CAP_THRESHOLD 800 // Capacitive reading that triggers keys
//#define NUM_OF_KEYS 4 // Number of keys that are on the keyboard

// This macro creates a capacitance “key” sensor object for each key on the game controller:
#define CS(Y) CapacitiveSensor(4, Y)

// Click to start game:
int mouse = MOUSE_RIGHT;
// Define pin connected to mouse:
CapacitiveSensor mouseSensor = CS(3) ;
// Each key corresponds to an arrow:
int keys[]={KEY_UP_ARROW, KEY_LEFT_ARROW, KEY_RIGHT_ARROW};
// Defines the pins that the keys are connected to:
CapacitiveSensor pins[] = {CS(2), CS(1), CS(5)};

void setup() {
// Turn off autocalibrate on all channels:
for(int i=0; i<4; ++i) {
pins[i].set_CS_AutocaL_Millis(5000);
}
Serial.begin(9600);

}

void loop() {
// // If the capacitance reading is greater than the threshold, mouse click to start game:
if(mouseSensor.capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {
Mouse.click();
delay(100);
Mouse.release();
}

// Loop through each key:
for (int i = 0; i < 4; ++i) {
// If the capacitance reading is greater than the threshold, press corresponding keys:
if(pins[i].capacitiveSensor(NUM_OF_SAMPLES) > CAP_THRESHOLD) {
Keyboard.press(keys[i]);
delay(100);
Keyboard.release(keys[i]);
}
}
}

For the enclosure, I used a small cardboard box I found on the shop floor by the junk shelf and managed to fit everything inside:

For the controller pad, I designed an intuitive fingerboard similar to how we position our fingers when using the arrow keys. To start the game, the user simply moves their index finger over to tap the start button. I also downloaded the font from the game and used motifs like the landing point system to complement the game:

The cut-out fingers are backed with conductive fabric and foam for a more satisfying touch sensation:

References:

https://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense

https://www.arduino.cc/en/Tutorial/KeyboardAndMouseControl

https://www.pjrc.com/teensy/td_libs_CapacitiveSensor.html

https://learn.adafruit.com/plush-game-controller/the-code

http://www.instructables.com/id/Capacitive-Touch-Arduino-Keyboard-Piano/

Leave a Reply

Your email address will not be published. Required fields are marked *