Skip to content

Commit d60c124

Browse files
authored
Add files via upload
1 parent 4b5bb6b commit d60c124

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

avdweb_VirtualDelay.ino

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright (C) 2016 Albert van Dalen http://www.avdweb.nl
3+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
4+
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
6+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at http://www.gnu.org/licenses .
7+
8+
Version 10-1-2016
9+
Version 6-9-2017 elapsed(), added start()
10+
Version 19-9-2017 DO_ONCE without class
11+
Version 19-9-2017 fix rollover bug
12+
13+
start _____|_____________________
14+
__________
15+
running _____| |__________
16+
17+
elapsed() ________________|__________
18+
19+
set timeOut _____|_____________________
20+
21+
*/
22+
23+
#include <Arduino.h>
24+
#include "avdweb_VirtualDelay.h"
25+
26+
VirtualDelay::VirtualDelay(unsigned long (*timerFunctionPtr)()):
27+
timerFunctionPtr(timerFunctionPtr)
28+
{
29+
}
30+
31+
void VirtualDelay::start(signed long delay) // 0...2^31
32+
{ if(!running)
33+
{ running = 1;
34+
timeOut = (*timerFunctionPtr)() + abs(delay);
35+
}
36+
}
37+
38+
bool VirtualDelay::elapsed()
39+
{ bool pulse = 0;
40+
if(running)
41+
{ //if((signed long)(*timerFunctionPtr)() >= timeOut) // bug, not equal to:
42+
if((signed long)((*timerFunctionPtr)() - timeOut) >= 0) // fix rollover bug: https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover/12588#12588
43+
{ running = 0;
44+
pulse = 1; // return 1 just one time
45+
}
46+
}
47+
return pulse;
48+
}
49+
50+
51+
52+
53+
54+
55+

keywords.txt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#######################################
2+
# Syntax Coloring Map For avdweb_VirtualDelay
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
avdweb_VirtualDelay KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
start KEYWORD2
16+
elapsed KEYWORD2
17+
18+
#######################################
19+
# Instances (KEYWORD2)
20+
#######################################
21+
22+
running KEYWORD2
23+
24+
#######################################
25+
# Constants (LITERAL1)
26+
#######################################
27+

library.properties

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=avdweb_VirtualDelay
2+
version=19.9.2017
3+
author=Albert van Dalen
4+
maintainer=Albert van Dalen <[email protected]>
5+
sentence=Allows using (multiple) delays without blocking code execution. Arduino Uno and Zero.
6+
paragraph=During the delay, the code execution is continued. We can use multiple delays simultaneously and independent of each other.
7+
category=Timing
8+
url=https://github.com/avandalen/VirtualDelay
9+
architectures=atmelavr, atmelsam
10+

0 commit comments

Comments
 (0)