56 lines
1.3 KiB
C
Raw Normal View History

2020-11-27 11:10:47 +01:00
#pragma once
//
// FILE: CountDown.h
// AUTHOR: Rob Tillaart
2023-10-19 09:41:18 +02:00
// VERSION: 0.3.2
// PURPOSE: CountDown library for Arduino
2020-11-27 11:10:47 +01:00
// URL: https://github.com/RobTillaart/CountDown
2021-01-29 12:31:58 +01:00
#include "Arduino.h"
2020-11-27 11:10:47 +01:00
2023-10-19 09:41:18 +02:00
#define COUNTDOWN_LIB_VERSION (F("0.3.2"))
2021-01-29 12:31:58 +01:00
class CountDown
{
public:
2023-03-14 17:30:31 +01:00
enum Resolution { MICROS = 'u', MILLIS = 'm', SECONDS = 's', MINUTES = 'M' };
2023-03-14 17:30:31 +01:00
explicit CountDown(const enum Resolution res = MILLIS);
2023-03-14 17:30:31 +01:00
void setResolution(const enum Resolution res = MILLIS);
enum Resolution resolution() { return _res; };
char getUnits();
2021-01-29 12:31:58 +01:00
2023-03-14 17:30:31 +01:00
// one need to set the resolution before calling start(ticks).
bool start(uint32_t ticks);
// Implicit set resolution to SECONDS.
bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds);
// Implicit set resolution to MINUTES.
bool start(uint8_t days, uint16_t hours, uint32_t minutes);
2021-01-29 12:31:58 +01:00
2023-03-14 17:30:31 +01:00
void stop();
void cont();
void restart();
2023-03-14 17:30:31 +01:00
uint32_t remaining();
bool isRunning();
bool isStopped();
2023-01-11 11:04:32 +01:00
private:
2023-03-14 17:30:31 +01:00
enum State { RUNNING, STOPPED };
uint32_t _ticks;
uint32_t _remaining;
enum State _state;
enum Resolution _res;
uint32_t _startTime;
void calcRemaining();
};
2021-10-19 21:40:11 +02:00
2023-01-11 11:04:32 +01:00
// -- END OF FILE --