Arduino HPDL1414 Retro Clock with Set and Alarm Functions
Unusual Retro clock that shows the time on retro displays made by Hewlett-Packard at the turn of the last century.
Components and supplies
1
Adafruit RTC DS3231 Real time clock
3
Push Button
1
Arduino Nano
1
Piezo Buzzer
Tools and machines
1
Soldering kit
Apps and platforms
1
Arduino IDE
Project description
Code
HPDL Code
cpp
..
1#include <HPDL1414.h> 2#include <RTClib.h> 3#include <Wire.h> 4 5const byte dataPins[7] = {2, 3, 4, 5, 6, 7, 8}; // Segment data pins: D0 - D6 6const byte addrPins[2] = {A1, A2}; // Segment address pins: A0, A1 7const byte wrenPins[] = {A0, A3}; // Write Enable pins (left to right) 8 9RTC_DS3231 rtc; 10char msg[] = " *** MICRO CLOCK - MIRCEMK *** "; 11char t[32]; 12HPDL1414 hpdl(dataPins, addrPins, wrenPins, sizeof(wrenPins)); 13 14// Button pins 15const int buttonHourPin = 9; 16const int buttonMinutePin = 10; 17const int buttonSetPin = 11; 18 19// Buzzer pin 20const int buzzerPin = 12; // Add a pin for the buzzer 21 22// Variables for setting time and alarm manually 23int hours = 0; 24int minutes = 0; 25int alarmHours = 0; 26int alarmMinutes = 0; 27bool setMode = false; // Time setting mode flag 28bool alarmMode = false; // Alarm setting mode flag 29bool alarmEnabled = false; // Alarm enabled flag 30bool alarmActive = false; // Alarm active (sounding) flag 31bool alarmAcknowledged = false; // Alarm acknowledged (stopped) flag 32 33// Buzzer timing 34unsigned long previousMillis = 0; 35const long beepInterval = 500; // 500ms on, 500ms off 36bool buzzerState = false; // To track buzzer state (on/off) 37 38void setup() { 39 Serial.begin(9600); 40 Wire.begin(); 41 hpdl.begin(); 42 hpdl.clear(); 43 44 // Set up buttons and buzzer 45 pinMode(buttonHourPin, INPUT_PULLUP); 46 pinMode(buttonMinutePin, INPUT_PULLUP); 47 pinMode(buttonSetPin, INPUT_PULLUP); 48 pinMode(buzzerPin, OUTPUT); 49 digitalWrite(buzzerPin, LOW); // Make sure the buzzer is off initially 50 51 // Display scrolling message at startup 52 for (byte i = 0; i < (sizeof(msg) / sizeof(char)); i++) { 53 for (byte j = 0; j < 16; j++) { 54 hpdl.setCursor(j); 55 if (i + j < (sizeof(msg) / sizeof(char))) { 56 hpdl.print(msg[i + j]); 57 } else { 58 hpdl.print(" "); 59 } 60 } 61 delay(200); 62 } 63 64 rtc.begin(); 65 // Initialize time variables from the RTC 66 DateTime now = rtc.now(); 67 hours = now.hour(); 68 minutes = now.minute(); 69} 70 71void loop() { 72 // Get the current time from the RTC 73 DateTime now = rtc.now(); 74 75 // Check if the alarm is active (buzzer sounding) 76 if (alarmActive) { 77 unsigned long currentMillis = millis(); 78 79 // Toggle the buzzer every 500ms (buzzerState controls on/off) 80 if (currentMillis - previousMillis >= beepInterval) { 81 previousMillis = currentMillis; // Save the last time the buzzer toggled 82 buzzerState = !buzzerState; // Toggle the buzzer state 83 digitalWrite(buzzerPin, buzzerState ? HIGH : LOW); // Turn the buzzer on or off 84 } 85 86 // Check if D11 is pressed to stop the alarm 87 if (digitalRead(buttonSetPin) == LOW) { 88 alarmActive = false; // Stop the alarm 89 alarmAcknowledged = true; // Mark the alarm as acknowledged 90 digitalWrite(buzzerPin, LOW); // Turn off the buzzer 91 delay(500); // Debounce delay 92 return; // Return to normal loop operation 93 } 94 } 95 96 // Check if we are in time or alarm setting mode 97 if (setMode) { 98 // Display the manually set time 99 sprintf(t, "%02d-%02d", hours, minutes); 100 hpdl.clear(); 101 hpdl.print(t); 102 103 // Check if buttons to adjust hours or minutes are pressed 104 if (digitalRead(buttonHourPin) == LOW) { 105 hours = (hours + 1) % 24; // Increment hours and roll over after 23 106 delay(200); // Debouncing 107 } 108 if (digitalRead(buttonMinutePin) == LOW) { 109 minutes = (minutes + 1) % 60; // Increment minutes and roll over after 59 110 delay(200); // Debouncing 111 } 112 } else if (alarmMode) { 113 // Display the manually set alarm time 114 sprintf(t, "A%02d-%02d", alarmHours, alarmMinutes); 115 hpdl.clear(); 116 hpdl.print(t); 117 118 // Check if buttons to adjust alarm hours or minutes are pressed 119 if (digitalRead(buttonHourPin) == LOW) { 120 alarmHours = (alarmHours + 1) % 24; // Increment alarm hours and roll over after 23 121 delay(200); // Debouncing 122 } 123 if (digitalRead(buttonMinutePin) == LOW) { 124 alarmMinutes = (alarmMinutes + 1) % 60; // Increment alarm minutes and roll over after 59 125 delay(200); // Debouncing 126 } 127 } else { 128 // Normal operation: Display the current time from the RTC 129 sprintf(t, "%02d-%02d-%02d", now.hour(), now.minute(), now.second()); 130 hpdl.clear(); 131 hpdl.print(t); 132 133 // Check if the current time matches the alarm time and alarm is not acknowledged 134 if (alarmEnabled && !alarmAcknowledged && now.hour() == alarmHours && now.minute() == alarmMinutes && now.second() == 0) { 135 alarmActive = true; // Mark the alarm as active 136 previousMillis = millis(); // Initialize the timer for buzzer beeping 137 } 138 139 // Reset the alarm acknowledgement flag if the minute has changed 140 if (now.minute() != alarmMinutes) { 141 alarmAcknowledged = false; // Allow the alarm to trigger again when the time matches next 142 } 143 } 144 145 // Check if the Set button (buttonSetPin) is pressed to toggle between modes 146 if (digitalRead(buttonSetPin) == LOW && !alarmActive) { 147 if (setMode) { 148 // Exiting time set mode, update the RTC with the manually set time 149 rtc.adjust(DateTime(2024, 1, 1, hours, minutes, 0)); // Arbitrary date 150 setMode = false; 151 alarmMode = true; // Move to alarm setting mode 152 } else if (alarmMode) { 153 // Exiting alarm set mode, enable the alarm 154 alarmEnabled = true; 155 alarmMode = false; // Back to normal mode 156 } else { 157 // Enter time setting mode 158 setMode = true; 159 } 160 delay(500); // Debouncing delay 161 } 162}
Downloadable files
Schematic
...
Schematic.png

Comments
Only logged in users can leave comments