{"id":20989879,"url":"https://github.com/robtillaart/timing","last_synced_at":"2025-05-14T18:32:22.920Z","repository":{"id":45235616,"uuid":"277785053","full_name":"RobTillaart/timing","owner":"RobTillaart","description":"Arduino library with wrappers for seconds millis micros ","archived":false,"fork":false,"pushed_at":"2024-04-13T09:17:54.000Z","size":31,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-07T18:27:05.648Z","etag":null,"topics":["arduino","microseconds","milliseconds","seconds"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-07-07T10:21:03.000Z","updated_at":"2024-01-25T19:35:52.000Z","dependencies_parsed_at":"2023-11-22T16:50:33.104Z","dependency_job_id":null,"html_url":"https://github.com/RobTillaart/timing","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2Ftiming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2Ftiming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2Ftiming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2Ftiming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/timing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225305755,"owners_count":17453441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","microseconds","milliseconds","seconds"],"created_at":"2024-11-19T06:26:34.521Z","updated_at":"2024-11-19T06:26:35.286Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":[],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/timing/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/timing/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/timing/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/timing/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/timing/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/timing.svg)](https://github.com/RobTillaart/timing/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/timing/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/timing.svg?maxAge=3600)](https://github.com/RobTillaart/timing/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/timing.svg)](https://registry.platformio.org/libraries/robtillaart/timing)\n\n\n# Timing\n\nArduino library with wrappers for seconds, milliseconds, and microseconds.\n\n\n## Description\n\nA request often made on the Arduino forum and otherwise is an option to reset\nthe **millis()** function to 0 or to another value.\n\nThis library provide wrapper classes around **millis()** and **micros()**\nwith the extra function to do reset the count by means of an offset.\nTo implement this only a 4 byte offset is needed per \"clock\".\n\nThe classes are based upon **millis()** and **micros()**.\nTherefore they have the same restrictions as these functions with respect to\noverflow and accuracy. Depending on e.g. interrupts, millis() and micros() can drift.\n\n\n|  class         |  overflow after            |  Notes                |\n|:---------------|:---------------------------|:----------------------|\n|  seconds       |  49 days, 17:02:47         |  based upon millis()  |\n|  milliSeconds  |  49 days, 17:02:47.297     |  based upon millis()  |\n|  microSeconds  |  00 days  01:11:34.967296  |  based upon micros()  |\n\n\n#### Tests\n\nCode is tested on UNO and ESP32, should work on all platforms.\n\nNo performance tests as code is 'basic'.\n\n\n## Applications\n\nThese classes make it easy to make a simple stopwatch, clock or countdown timer.\nIt is also possible to sync the time (e.g. millis()) with an external source,\nwhich could be another Arduino.\n\n\n## Interface\n\n```cpp\n#include \"timing.h\"\n```\n\nThe interface of all three are very similar:\n\n- **microSeconds()** constructor, sets the offset so it starts at 0.\n- **milliSeconds()** constructor, sets the offset so it starts at 0.\n- **seconds()** constructor, sets the offset so it starts at 0.\n- **uint32_t now()** returns the time elapsed since its 'zero moment'.\nEther set during construction or by a call to **set(0)**.\n- **void set(uint32_t value = 0UL)** sets the offset of the object.\nAs it is possible to set it to a non zero value it is easy to adjust the time.\nThis allows one e.g. to compensate for overhead. Default = zero.\n- **void add(uint32_t value)** allows one to increment or decrement the offset for calibration.\nAllows one to sync time e.g. with an external reference in small incremental steps.\n- **uint32_t getOffset()** returns current offset in base units.\nSo seconds for seconds, millis for millis and micros for micros.\n- **double toSeconds()** returns a float representation of the current value in seconds.\ne.g. 15678 milliseconds becomes 15.678 seconds (SI units).\n\n#### Experimental\n\n- ** char \\* toClock()** converts current seconds to a clock like char array \"HH:MM:SS\".\nOnly for the seconds class for now.\n\n\n## Future\n\n#### Must\n\n- update documentation\n  - describe rounding effect (seconds)\n\n#### Should\n\n- implement toClock()\n  - seconds.toClock() -\u003e DD 12:34:56  (days ??)\n  - milliSeconds.toClock(3) -\u003e 12:23:45.123    (3) == 3 decimals..\n  - milliSeconds.toClock(1) -\u003e 12:23:45.1\n  - microSeconds.toCLock()  -\u003e 12:23:45.123456  ???\n  - printHelpers class?\n\n\n```cpp\n  // something like this.\n  char * toClock()\n  {\n    static char buf[12];\n    uint32_t _now = now();\n    int hh = _now / 3600;\n    _now = _now - hh * 3600;\n    int mm  = _now / 60;\n    int ss = _now - mm * 60;\n    sprintf(buf, \"%02d:%02d:%02d\", hh, mm, ss);\n    return buf;\n  }\n```\n\n\n#### Could\n\n- nanos() on ESP32 ?\n  - measureable?\n- implement printable interface\n  - add unit (s, ms, us)\n  - what layout to use? (culture dependent)\n- create a uint64_t seconds type?\n\n#### Wont\n- move code to .cpp file?\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Ftiming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobtillaart%2Ftiming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Ftiming/lists"}