Hackaday Badge Nyan Cat: Simplicity Pays Off

poptartcat320240I’m adapting the Nyan Cat animation to the Hackaday Belgrade 2018 badge (close predecessor to the Hackaday Superconference 2018 badge) and I chose to simplify the animated GIF data to a simple run-length encoding. RLE doesn’t compress as much as GIF, but it makes the decode algorithm simple. A simple algorithm takes up little program memory on the PIC32, and more importantly, it takes up less of my time coding and debugging. The latter is quite important when I’m trying to do something within the timeframe of a single weekend, as most Supercon badge hackers do.

The simplicity paid off when I wrote the code – just a few lines and only a few variables – and ran it on my Belgrade badge. The first test only decoded part of the first frame. I was actually quite surprised when the face of a cartoon cat looked back at me from the badge LCD! It is rare when a chunk of code works immediately on the first try.

After the first partial frame was proven to work, I extended the for() loop to the entire image, then I wrote an infinite loop to cycle through all 12 frames of the animation. I made the design decision for code simplicity and it paid off tremendously. Drastically reducing the time spent on implementation and (quite unexpectedly) completely eliminated the time spent on debugging.

If I had tried to port a GIF decode library I’m certain I would have needed to spend more time getting the code to compile and run on the badge, and it would not have been fun to debug if anything should go wrong.

This project’s progress is publicly visible on Github.

(Cross-posted to Hackaday.io)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s