GY-63_MS5611/libraries/CountDown/CountDown.h

56 lines
1.3 KiB
C
Raw Normal View History

2020-11-27 05:10:47 -05:00
#pragma once
//
// FILE: CountDown.h
// AUTHOR: Rob Tillaart
2023-10-19 03:41:18 -04:00
// VERSION: 0.3.2
// PURPOSE: CountDown library for Arduino
2020-11-27 05:10:47 -05:00
// URL: https://github.com/RobTillaart/CountDown
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2020-11-27 05:10:47 -05:00
2023-10-19 03:41:18 -04:00
#define COUNTDOWN_LIB_VERSION (F("0.3.2"))
2021-01-29 06:31:58 -05:00
class CountDown
{
public:
2023-03-14 12:30:31 -04:00
enum Resolution { MICROS = 'u', MILLIS = 'm', SECONDS = 's', MINUTES = 'M' };
2023-03-14 12:30:31 -04:00
explicit CountDown(const enum Resolution res = MILLIS);
2023-03-14 12:30:31 -04:00
void setResolution(const enum Resolution res = MILLIS);
enum Resolution resolution() { return _res; };
char getUnits();
2021-01-29 06:31:58 -05:00
2023-03-14 12:30:31 -04: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 06:31:58 -05:00
2023-03-14 12:30:31 -04:00
void stop();
void cont();
void restart();
2023-03-14 12:30:31 -04:00
uint32_t remaining();
bool isRunning();
bool isStopped();
2023-01-11 05:04:32 -05:00
private:
2023-03-14 12:30:31 -04: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 15:40:11 -04:00
2023-01-11 05:04:32 -05:00
// -- END OF FILE --