Write messages with your Touch Board – or control games!
Have you ever wanted to use your Touch Board as an HID keyboard input to your computer? You might want it to control your favourite online arcade game, or act a bit more like a Makey Makey (but only needing one hand to actuate!). Or maybe you have another use in mind that requires keypresses. Either way, follow the steps below and soon you will be typing away via the power of capacitive touch.
For more project ideas visit www.bareconductive.com
Step 2: Download the HID Keyboard Code
This tutorial assumes you already have Arduino installed and set up to work with the Touch Board. If not, follow the link below and come back here once you have everything set up.
We need to reprogram the Touch Board in order to make it work like a keyboard and map the electrodes to keystrokes. Luckily, we have already written this code, so all you need to do is download it at the link below, unzip it and put the HID_Keyboard folder in your Arduino Sketchbook folder:
WindowsLibraries/Documents/Arduinoor My Documents/Arduino MacDocuments/Arduino Linux (Ubuntu) Home/Arduino
Step 3: Upload the Code to the Touch Board
Plug the Touch Board into the computer via the USB cable. Make sure that the power switch on the board is set to ON.
Open the Arduino IDE and then open the HID_Keyboard sketch from your Sketchbook. Ensure that Bare Conductive Touch Board is selected under Tools->Board and that the correct serial (TTY) port is selected under Tools->Port.
Click File->Upload to push the code to the Touch Board. The RX and TX LEDs will flash on the Touch Board and the Arduino IDE should say “Done uploading.”
Step 4: Test the Code Out!
Open up a text editor, such as TextEdit, Gedit or Notepad. Touching E0 on the Touch Board will output the letter J, which you should see on the text editor screen. Going from E0 to E11 you should see:
J U H Y G T F D E S W A
If this works – congratulations, you have the code working! If you open Garage Band and press each electrode in turn, you will hear a scale being played. You may notice that there is no R in the string of letters above – this is due to the way that Garage Band maps keys to notes. We chose the default letters in the code to skip R so that it works well with Garage Band – but you can change them to whatever you like in the step below.
If you are having difficulties, double-check that the board is switched on, and try re-uploading the code to the board. You may have to press and hold the reset button, releasing it only when the Arduino IDE says uploading.
Step 5: Now Modify It
So this is great, if the letters that we chose are your favourites, but what if they are not? No worries – you can easily change them by editing the keyMap variable on line 34 of HID_Keyboard.ino.
You can see an example of some non-printing keyboard strokes on line 35, and the Arduino Keyboard Modifiers Reference link here has lots of other valid keystrokes to choose from. The position of the key within the brackets determines its mapping – the first in the array maps to E0, the second to E1 and so on. Don’t put more than 12 different items in the array or the code won’t work. Also, don’t forget that normal letters need single quotes around them, like ‘A’ whereas special keys are named constants like KEY_F1 (the “F1” key on your keyboard).
Step 6: Wanna Play Some Games?
Now that we have the keyboard code working, and can map it to whichever keys we like best, what should we do with it? As we previously mentioned, the stock code works well with GarageBand to play a simple scale, but what else could you do?
There are loads of online games out there that use the keyboard to control them. One of our favourites is Doodle. This uses the left and right, up and down arrow keys to control your character’s movement, and space to fight baddies. So let’s use the Touch Board to control that!
In HID_Keyboard.ino, uncomment line 35 to use an alternative key map. You do this by removing the // at the beginning of the line. Also, you should comment out line 34 (add // at the start of the line) – this will cause this code (the default map) to become greyed out and not active. If you now upload the modified code to the Touch Board, the first 5 electrodes (E0 to E4) will control the character – take a close look at line 35 to work out which does what.
Now go to the website linked below and you should be able to control the game with your Touch Board. Once this is working, you can start to design your own custom gamepad or controller using Electric Paint and cardboard – or maybe something more fancy!
If you liked this tutorial visit www.bareconductive.com for more!