top of page
Search
  • Writer's picturefezec

An Endless Runner


There is an adage, "To a man with a hammer, everything looks like a nail."


This adage is often said with negative connotation. However, simplicity and repetition is a fundamental part of learning. That being said, since I have not yet filled my tool box with tools beyond my hammer, this next project continues to build upon my previous learnings.

About the Build

I recently played an endless runner on my phone. The point of the game is simple- Run! More specifically, run until there is a need to jump over an obstacle. Jumping in this case is the result of tapping anywhere on the screen. One day while playing I had an epiphany. I knew that it was possible to attach a keyboard directly to my android device as a Human Input Device (HID) and set out to trigger my in game character to jump when doing so in real life. I quickly reached for my proverbial 'hammer' to devise a Proof of Concept.

As a down 'n dirty solution, I reached for my Makey Makey, a singular pressure sensing matt, a few electrical jumpers, my android phone and, lastly, installed Apocalypse Runner from the Android Play Store.

After having setup the hardware, and plugging it in to my phone, it became immediately obvious that my behavior was backwards. Stepping onto the mat caused the in-game character to jump, while stepping off the mat or jumping had no effect. It was clear the current behavior was the inverse of what I strived to achieve.

What was happening was the following: Stepping on the pressure mat closed the circuit, thereby sending a high signal to the Makey Makey. This in turn forwarded the event to the phone causing the character to jump. While this is not the desired response, the behavior is easily understandable. The Makey Makey is enabled when the signal is HIGH. Thus standing on the mat, which closes the circuit, causes the Makey Makey to see a High Signal. The Makey Makey then relays this HIGH signal to my phone as a jump command-causing the character to jump.

In order to achieve my goal, I would need to invert the current behavior.

In other words- Standing on the matt needs to maintain a LOW signal, while jumping off the mat must generate a HIGH signal.

Determined to solve this matter the same day, I sought the answer in a Single-Pole Double-Throw Relay that I had lying around from my Sparkfun Arduino kit from several years back. I emphasize Double-Throw in the prior sentence, because this is what will allow us to achieve the inverted behavior. You see, a Single-Pole Double-Throw switch has the ability to open or close 2 circuits using a single contact, but never at the same time. This is due to the Single-Pole. This is easy to illustrate using the below image:


Because only 1 circuit can be closed at a time in a Double-Throw switch, we can say that we have in essence 2 switches. One that is normally-open (the opposite side of the closed switch) and one that is normally-closed (the side that has the switch touching the contacts). With that out of the way, we simply need to hook our makey makey up as a normally-closed switch thus inverting our game behavior circuit.

One thing worth noting is that a Relay does not require you to manually move a switch to open/close a circuit. Instead, the switching behavior is activated by 5V.

Materials Required:

1 Makey Makey board

several alligator clips

5 volts (4 Double A batteries)

3 volts (2 Double A batteries)

1 Single Pole - Double Throw (SPDT) 5V relay (JZC-11F)

1 LED

1 350 ohm resistor


The image above reveals 2 circuits.

Circuit 1 consists of a Relay and 5v (4 AA batteries) which are currently disconnected from several alligator clips. The second circuit consists of 1 LED and 1 350 ohm resistor powered by 3v (2 AA batteries).

The relay of the first circuit is attached inline to our second as a Normally-Closed switch. This enables the LED to remain on as long as the 5v remain disconnected from the Relay. However, once we close the path between the Relay and the 5V, the Pole on the relay will open the path between the LED and its power source. In other words, the application of electricity to the relay acts as digital switch that effectively inverts the signal to the LED. My crude prototype can be viewed in the video below.


Rather than connecting the 5V to the Relay using an alligator clip, I will instead employ my Pressure Sensing Matt. Standing on the mat causes our secondary circuit to open, while Jumping off the mat causes it to close. Providing us the expected behavior.

The final step is to simply place the Makey Makey inline with the secondary circuit. Viola, We have created our own interactive arcade.

Failures

While the Relay provided the necessary inverted behavior, there was a noticeable delay between my actual jump and the in-game character jump. If I had to guess, I'd assume this is due to the mechanical behavior of the relay. It is not truly digital but rather mechanical. While this was a great go-round, I do view this as a failure that would need improvement.

Lessons Learned

A problem encountered can be the best motivator or hinderance. In this particular case it was a great motivator.

While I did manage to accomplish my goal of triggering an in game jump by jumping in real life, it seemed that it could be greatly improved. This led me to learn of new ways in which I could invert a signal using solid state devices such as the npn222 transistor.

The transistor has a unique ability to take input from terminal 'A' known as the Collector, and input from terminal 'B' known as the Base. The amount of current provided to terminal 'B' is directly proportional to how much of the current from terminal 'A' can pass through terminal 'C' known as the Emitter,

Effectively enabling a solid state inverter.

This method provided low latency to my HID and is now another tool in my tool box.



7 views0 comments

Recent Posts

See All
bottom of page