This repository was archived by the owner on Jul 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathautoDelay.h
More file actions
119 lines (61 loc) · 3.45 KB
/
Copy pathautoDelay.h
File metadata and controls
119 lines (61 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*--------------------------------------autoDelay.h Library -------------------------------
Simple method for timing events without using interrupt based delay functions
autoDelay != delay();
functions include delays passed values in:
Micro & Milliseconds,
Seconds, and Minuites.
Makes timing events a piece of cake.
Written by Imogen Heard. 09/08/2020
Released into Public Domain
Free to Distibute and Use.
*/
#ifndef autoDelay_h
#define autoDelay_h
#if (ARDUINO >=100)
#include <Arduino.h>
#else
#include <wProgram.h>
#endif
class autoDelay
{
public:
// Constructor
autoDelay();
// Methods
void begin(); // depreciated to use with ATtiny
// Basic Methods (Origional - depreciated but remain for backwards compatability)
bool millisDelay(uint32_t delayTime); // delay function using Milliseconds
bool microsDelay(uint32_t delayTime); // delay function using Microseconds
bool secondsDelay(uint32_t delayTime); // delay function using Seconds
bool minutesDelay(uint32_t delayTime); // delay function using Minutes
void resetDelayTime_mS(); // Sets the previousTime variable to the current time in millis() (for all delays except micros)
void resetDelayTime_uS(); // Sets the previousTime variable to the current time in micros() (for microS delays)
// delayEvent Loop Methods
bool millisDelayEvent(uint32_t delayTime); // delay function using Milliseconds
bool microsDelayEvent(uint32_t delayTime); // delay function using Microseconds
bool secondsDelayEvent(uint32_t delayTime); // delay function using Seconds
bool minutesDelayEvent(uint32_t delayTime); // delay function using Minutes
// delayEvent Control Methods
void startDelay(int16_t repeats = -1);
void startIndefinate();
void stopDelay(bool resetRepeats = true); // Stops a delayEvent with the option to reset eventCounter. defaults to true
void pauseDelay(); // Pauses delayEvent and does not reset eventCounter
void restartDelay(int16_t additional = 0); // Restarts delayEvent with the option to add in additional events. Defaults to 0
void addCounter(int16_t additional = 1); // Method to add additional events to delayEvent without pausing, or restarting delayEvent. Default adds 1
// Can be passed negative arguments to subtract events left.
// Safe function, if number of events subtracted are less than remaining events, defaults to 0,
// else could trigger indefinate repeats. If indefiniate repeat is desired, use startDelay(-1) or startIndefinate();
// Adding additional events to an indefinate delay event could lead to incorrect values. Best to use startDelay(X);
// Depreciated Methods
bool delayScript(uint32_t delayTime); // Old delay function left in to maintain backwards compatability
// Variables
bool delayActive = false;
int16_t eventCounter = 0;
private:
//Methods
bool globalDelay(uint32_t currentTime, uint32_t delayTime); // Global delay method called by all other methods (as architecture is largely the same)
bool delayEvent(uint32_t currentTime, uint32_t delayTime); // Global delayEvent method called by all other delayEvent methods
// Variables
long previousTime;
};
#endif