[conn-dev wk 3] Buttons! Screens! Keyboard! Pokemon!

This week, we were asked to create a Human Interface Devices (HID) with an Arduino, emulating a USB keyboard or mouse using the Keyboard and Mouse libraries.

Last semester I found some cherry arcade buttons and joysticks on the floor, and it finally feels like the perfect day to try them out!! Here are three iterations of using the buttons as keyboard:

1. Left / Right / Up arrow keys to control lunar landing game

(I somehow got super good at the game so now you have to sit through my entire 4 minutes of game play)

We were encouraged to try to control lunar lander, a beautiful browser game.

The code was fairly simple, because it didn’t require any state change detection. In the game, players hold down left, right and up arrows for turning and thruster (?) — I noticed that there seems to be some sort of bezier curve that smooths out the action, and it’s likely that a player of this game would a) hold down two keys at a time; b) continue pressing on keys for extra speed boost.

Unlike typing characters, this would require keyboard modifiers. I used Keyboard.press(KEY_RIGHT_ARROW) inside of a button pressed condition, and Keyboard.release(KEY_RIGHT_ARROW) in else{} (same goes to the other two keys). I also secretly exchanged left and right buttons’ functions because I find the turning in the game not very intuitive. I guess the arrow keys in the game assumed you’d want to press left when turning your rocket to FACE left, but I see it more like a car parking situation, where I hit left to turn my TAIL left.

Pushing bigger, more pleasant buttons, as well as using both hands with edges of the box to hold onto like a game controller, made a huge impact on my gameplay experience. Definitely better than tiny keyboard arrows!

2. Happy typewriter that only types “ha”

In order to use the buttons as typewriters, I added state detection, and used Keyboard.print(). The issue was when I tried to print multiple characters, for example, Keyboard.print('zebra'), I get a string of numbers instead; however, when I use double quotations like Keyboard.print("zebra"), it prints the texts as a string.

3. Pick Your Pokemon (I2C OLED Display)

With the help of Tom’s Display Examples, I tried out displaying different messages on the OLED screen, and started looking into ways to design the display. The retro feeling of this screen reminds me of playing Pokemon as a child — so I sought out this Bitmap Converter and transformed some 128 x 64 images into Bitmap.

I tried to make a “single click – reveal, double click – select” interaction, but the logic turned out to be much difficult than I thought. As a compromise, I made the screen display an opening message (“PICK YOUR POKEMON” in a nice square), and the buttons only function as single clicks, triggering images then inverting them after 50ms.

Code available on GitHub!

Finally, attaching the Adafruit box fabrication:

Someday, eventually, I’ll try a full color TFT LCD screen.

Leave a Reply

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