-
Notifications
You must be signed in to change notification settings - Fork 1
/
flash.cpp
51 lines (46 loc) · 1.4 KB
/
flash.cpp
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
#include "flash.h"
void Flash::setPin(int _pinNumber){
this->pinNumber = _pinNumber;
pinMode(this->pinNumber, OUTPUT);
}
void Flash::dFlash(unsigned long flashPeriod) {
digitalWrite(pinNumber, HIGH);
delay(flashPeriod);
digitalWrite(pinNumber, LOW);
delay(flashPeriod);
}
void Flash::dFlashes(unsigned long flashPeriod, int flashCount){
int c = 0;
while( c < flashCount ) {
dFlash(flashPeriod);
c++;
}
}
void Flash::ndFlash(unsigned long _flashPeriod, int _numFlashes){
if (this->flashInProgress == 0) {
this->flashInProgress = 1;
this->flashPeriod = _flashPeriod;
this->numFlashes = _numFlashes;
this->flashCounter = 0;
}
this->ndWatcher();
}
void Flash::ndWatcher() {
if (this->flashInProgress >= 1) {
unsigned long currentMillis = millis();
if (this->flashInProgress == 1) {
digitalWrite(this->pinNumber, HIGH);
this->flashStartTime = currentMillis;
this->flashInProgress = 2;
} else if (currentMillis - this->flashStartTime >= this->flashPeriod and this->flashInProgress == 2) {
digitalWrite(pinNumber, LOW);
flashInProgress = 3;
} else if (currentMillis - this->flashStartTime >= this->flashPeriod * 2 and this->flashInProgress == 3) {
this->flashCounter++;
if (this->flashCounter < this->numFlashes){
this->flashInProgress = 1;
}
this->flashInProgress = 0;
}
}
}