Skip to content

manzarehassin/softRTC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

softRTC

License: MIT

A lightweight, software-based real-time clock (RTC) library for Arduino and compatible microcontrollers. This library allows you to maintain date and time (hours, minutes, seconds, day, month, year) without needing dedicated RTC hardware modules. It supports both 12-hour (AM/PM) and 24-hour modes, calculates weekdays, and offers a straightforward API for time manipulation.


Table of Contents


Features

  • Software RTC: Maintains date/time using millis() – no additional hardware required.
  • 12-Hour / 24-Hour Modes: Easily switch between standard (AM/PM) or 24-hour (military) time.
  • Weekday Calculation: Automatically determines the weekday (Sun–Sat).
  • Serial Output: Built-in print() function for quick debugging or logging.
  • Minimal Footprint: Designed to be lightweight for memory-constrained devices.

Installation

Manual Installation

  1. Click the green “Code” button on this GitHub repository and select Download ZIP.
  2. Extract the ZIP file on your computer.
  3. Rename the extracted folder to softRTC (if it isn’t already).
  4. Move the softRTC folder into your Arduino libraries directory:
    • Windows: Documents\Arduino\libraries\
    • macOS: ~/Documents/Arduino/libraries/
    • Linux: ~/Arduino/libraries/
  5. Restart the Arduino IDE if it was open.

Usage

Basic Steps

  1. Include the Library

    #include <softRTC.h>
  2. Create an RTC Object

    softRTC myRTC;
  3. Set the Time

    // write(day, month, year, hour, minute, second, isPM, is12HMode)
    // Example: set 10:15:30 AM, 21 March 2025 in 24-hour mode
    myRTC.write(21, 3, 2025, 10, 15, 30, false, MODE_24H);
  4. Read the Time

    uint8_t d, m, h, min, s, weekday;
    uint16_t y;
    bool pm, is12;
    myRTC.read(d, m, y, h, min, s, pm, is12, weekday);
    // Now you can use these variables in your code...
  5. Print the Time

    myRTC.print(); // e.g., "21-3-2025 10:15:30 24H Fri"
  6. Check Sync Status

    if (!myRTC.syncStatus()) {
      // If false, the clock isn't set or has invalid data
    }

Example Sketch

#include <softRTC.h>

softRTC myRTC;

void setup() {
  Serial.begin(9600);
  // Set the time to 9:30:45 PM, 21 March 2025 in 12-hour mode
  myRTC.write(21, 3, 2025, 9, 30, 45, true, MODE_12H);
}

void loop() {
  // Print the current time every second
  static unsigned long lastUpdate = 0;
  if (millis() - lastUpdate >= 1000) {
    lastUpdate = millis();
    myRTC.print();
  }
}

Contributing

Issues / Feature Requests
If you run into any problems or have ideas for improvements, please open an issue on GitHub.

Pull Requests

  • Fork the repository and create a branch for your changes.
  • Make commits with clear and descriptive messages.
  • Submit a pull request explaining what you changed and why.

Code Style
Follow the existing code structure. If you add a feature, include an example or documentation update.


License

This library is released under the MIT License.
See the LICENSE file for details.


Author

Manzar E Hassin

Feel free to reach out with questions, feedback, or to share any projects using softRTC!

About

Lightweight Software based real time clock

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages