Tero's Arduino Blog

Using Arduino with Ada

Counting seconds with attiny4313

AVR-Ada includes AVR.Real_Time package and separate AVR.Real_Time.Clock function, whose job is to return the current time. On Arduino, the current time means seconds from the device bootup, in other words it tells you how long the device has been on.

Relevant code is following

with AVR.Real_Time;
with AVR.Real_Time.Clock;
use AVR.Real_Time;

Start_Time : AVR.Real_Time.Time;
Start_Time := AVR.Real_Time.Clock;
if AVR.Real_Time.Clock - Start_Time > 1.0 then
end if;

When you combine this information with the 7-segment display, you can create a simple counter:

Adding buttons to reset/stop time is left as an exercise for the reader :).

Code is at bitbucket. Notice that the repository is arduino-mega2560-4d-7segment and the branch is this time attiny4313. This is mostly because I was lazy and didn't want to create a separate repository for this simple demo.

To get the code with Mercurial you need to do:

hg clone https://bitbucket.org/tkoskine/arduino-mega2560-4d-7segment
cd arduino-mega2560-4d-7segment
hg update attiny4313

Copyright © 2012, 2013 Tero Koskinen - Theme Skeleton; Blogging engine Pelican; Powered by Python