DIY Apple Clock

The ATtiny24, 44, 84 series only has 1 external interrupt (INT0) [Page 48 of the datasheet]. This is the interrupt that we are most familiar with using on the Arduino. You can simply use this interrupt by saying “attachInterrupt()”
While it only had 1 interrupt, I wanted to have two buttons on my clock: one button to increase the time and another to decrease the time. Looking back on the datasheet, the ATtiny has two Pin Change Interrupt ports: PCINT0 and PCINT1 [Page 48].
The difference between External Interrupts and Pin Change Interrupts is that an External Interrupt has its own ISR (interrupt service routine). PCINTerrupts share one ISR for all pins on one port. This means that with Pin Change Interrupts we can make any pin be an interrupt, but then we have to go through the trouble of determining which pin caused the interrupt on the port.
Here are two really good articles to read. This is how I learned:

volatile int dig1 = 0;    //Hours tens
volatile int dig2 = 0;    //Hours ones
volatile int dig3 = 0;    //Minutes tens
volatile int dig4 = 0;    //Minutes ones

Each of these variables determines what number is displayed on each of the four digits on the bubble display.
I declared them volatile because they will be changed in the interrupt routines.
Setting them to 0 means when I turn on my clock, the count will start at 00:00 (12:00 AM).

const int latchPin = A3;  //Pin connected to ST_CP of 74HC595
const int clockPin = A4;  //Pin connected to SH_CP of 74HC595
const int dataPin = A5;   //Pin connected to DS of 74HC595

Physical pins 8(A5), 9(A4), and 10(A3) will be used with the 74HC595 shift register.
The shift register will allow us to control segments a, b, c, d, e, f, g, and dp with pins Q0, Q1, Q2, Q3, Q4, Q5, Q6, and Q7 respectively.
To display each digit, we will be multiplexing.

const int dig1Pin = A0;  //Pin to multiplex and display digit1
const int dig2Pin = A1;  //Pin to multiplex and display digit2
const int dig3Pin = A2;  //Pin to multiplex and display digit3
const int dig4Pin = A6;  //Pin to multiplex and display digit4

The bubble display is common cathode. This means that when the digit is grounded or pulled to a digital LOW, the digit will light up. We will be using physical pins 13(A0), 12(A1), 11(A2), and 7(A6) to control the display of each digit on the bubble display.

//Two values below for debouncing.
volatile unsigned long xlastDebounceTime = 0;
volatile unsigned long ylastDebounceTime = 0;
long debounceDelay = 150; // the debounce time; increase if the output flickers

These are some values we will be using to debounce the two buttons when the interrupt is activated. Without debouncing, one button press could be registered as five, and using the clock would be annoying.
Check out Arduino Examples/Digital/Debounce if you want.
For more detail: DIY Apple Clock


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top