Stokes' ProjBlog

A journal documenting innumerable, mostly terminally in-progress undertakings. Nerdiness abounds.


Hanging on the Telephone, Part 2: the Code September 26, 2013

Filed under: Miscelaneous Projects — Stokes @ 3:05 pm

Rotary Dial w/ DigisparkTurning a rotary telephone dial into a USB device was easy. As I (re-)discovered, the dial is basically just a pair of switches: a normally-open ‘dialing’ switch, which closes while the dial is in motion, and a normally-closed ‘pulse’ switch, which opens and closes the same number of times as the number dialed. All I needed to do was count the number of pulses that occur while the ‘dialing’ switch is closed, then send a USB keypress event based on that number when the ‘dialing’ switch opens again.

I used a Digispark for this project, so the code reflects a few of its oddities. In order to cram software USB emulation onto a tiny microcontroller and still leave room for user code, they had to make some compromises. There are no interrupts available, and their own version of the delay() function needed to be used to keep everything in sync. The hardware side is also a little odd: because the Digispark’s main header doesn’t provide a ground connection, I just set one of the digital I/O pins LOW and used that. This seemed like a hack at the time, but I later saw this technique on one of Digistump’s own lists of power user tips, so I don’t feel so bad.

Here’s the code:


Leave a Reply

You must be logged in to post a comment.