A project log for Trinket Watch

A watch with an OLED display, powered by a Trinket

davishdavish 12/21/2014 at 20:390 Comments

From now until Wednesday, I won't be around to work on the physical watch. The same will be true from Saturday through New Years. Such are the holidays. So, to make sure I'm not completely wasting my time, I decided to write an emulator to test on. You can find it at it's current stage on Dropbox, and check out the source in this project's GitHub Repo. Both links are in the sidebar.

It turns out Adafruit's Graphics Library doesn't have any documentation to my knowledge: I have to find out how shapes are drawn by writing the code and testing it out on the display itself. Not wanting to wait four days to get something done, I decided to write a little emulator for the OLED display.

A while back, I wrote an implementation of Snake in JavaScript, splitting up an HTML5 canvas into a grid, and individually setting the pixels on that grid to different colors. To draw the game. Looking at the code for the Adafruit library, it turns out that all of the shapes are drawn onto the screen at the basic level using a function called drawPixel(), which I'd already written for my snake game. With a little bit of improvement on my original code, and JavaScript ports of drawLine() and drawCircle() from the original C++ source, I had a 128x64 pixel white-on-black display being simulated in my browser window. Next thing I knew, I had a smiley face staring back at me:

I also implemented the Arduino function millis(). Between that and the JavaScript Date object, I should be able to emulate the RTC as well as the display. The next thing to do with this emulator is probably to add the three navigational buttons, and start writing code for an analog clock, and then move onto Pong.

The main limitation of the emulator right now is that I can't print text such that it will look and behave the same as on the OLED display. The real library uses a 1KB buffer that's a bitmap of the display; mine just draws straight on the canvas. Because of this, it would take a little more work than I feel is justified to get the ASCII bitmap working with the emulator. I'll use it to get the components that need to have shapes drawn (such as an analog clock or Pong) implemented, but things like the stopwatch and the main menu will have to wait until I get back to the physical watch to be implemented. But if I really get into it, I might implement the buffer and actually make the emulator do everything the final Trinket Watch will be able to do.