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

55 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-01-11 05:04:32 -05:00
// VERSION: 0.3.0
// 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-01-11 05:04:32 -05:00
#define COUNTDOWN_LIB_VERSION (F("0.3.0"))
2021-01-29 06:31:58 -05:00
class CountDown
{
public:
2023-01-11 05:04:32 -05:00
enum Resolution { MICROS = 'u', MILLIS = 'm', SECONDS = 's', MINUTES = 'M' };
explicit CountDown(const enum Resolution res = MILLIS);
2021-01-29 06:31:58 -05:00
void setResolution(const enum Resolution res = MILLIS);
2023-01-11 05:04:32 -05:00
enum Resolution resolution() { return _res; };
char getUnits();
2021-01-29 06:31:58 -05:00
2023-01-11 05:04:32 -05:00
// one need to set the resolution before calling start(ticks).
2021-01-29 06:31:58 -05:00
bool start(uint32_t ticks);
2023-01-11 05:04:32 -05:00
// Implicit set resolution to SECONDS.
2021-01-29 06:31:58 -05:00
bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds);
2023-01-11 05:04:32 -05:00
// Implicit set resolution to MINUTES.
2021-01-29 06:31:58 -05:00
bool start(uint8_t days, uint16_t hours, uint32_t minutes);
void stop();
void cont();
uint32_t remaining();
2021-01-29 06:31:58 -05:00
bool isRunning();
2023-01-11 05:04:32 -05:00
bool isStopped();
private:
enum State { RUNNING, STOPPED };
2020-11-27 05:10:47 -05:00
uint32_t _ticks;
uint32_t _remaining;
enum State _state;
enum Resolution _res;
2023-01-11 05:04:32 -05:00
uint32_t _startTime;
2020-11-27 05:10:47 -05:00
void calcRemaining();
};
2021-10-19 15:40:11 -04:00
2023-01-11 05:04:32 -05:00
// -- END OF FILE --