Close

Logic code: finished

A project log for Darktimer

A countdown timer for use when you can't have any light. Multiple sequential timers stored in EEPROM, with coded beeps to indicate events.

Dangerpants LabsDangerpants Labs 08/17/2015 at 23:050 Comments

This weekend saw the "feature complete" stage for logic code. 1283 lines of code, and 1709 lines of test code. With any luck, those 1283 lines will compile down into something that will still fit in the flash storage of an ATMega328P, though I haven't tried yet. It gives me a good appreciation for how much code surrounds us: this timer is pretty straightforward, and it still took many hours to write, and occupies (an admittedly somewhat sparse) 1283 lines.

The logic code is basically everything that can be written without having the hardware in front of me. All the display stuff, timer manipulation, beep manipulation, button presses (via interrupt variables), etc. The hardware layer will be its own challenge, although there are only 8 function calls that will hook up to hardware (read and write EEPROM, tone on and off, start and stop a 1 second timer, get millis, and set a line on the display). These are all things that I've dealt with before, but never all at once.

I know the Arduino Tone library (which I'm hoping to use) takes up a timer, and I believe the millis() function takes up another, which should fill up the timers available on the 328. So I'm not sure if I'm going to have trouble trying to set a 1s interrupting timer.

One thing I'd like to do, but may not be able to just yet, is to put the CPU to sleep until the next interrupt comes in. The buttons and 1s timer are all designed as interrupts with this in mind, but I've never done any low-power work on a microcontroller, so I expect to have some challenges getting that to work. The battery will last a whole lot longer if the CPU can sleep between ticks and button presses.

Discussions