-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflasher.h
49 lines (44 loc) · 1.43 KB
/
flasher.h
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
class Flasher
{
// Class Member Variables
// These are initialized at startup
int ledPin; // the number of the LED pin
long OnTime; // milliseconds of on-time
long OffTime; // milliseconds of off-time
// These maintain the current state
int ledState; // ledState used to set the LED
unsigned long previousMillis; // will store last time LED was updated
// Constructor - creates a Flasher
// and initializes the member variables and state
public:
Flasher(int pin, long on, long off)
{
ledPin = pin;
pinMode(ledPin, OUTPUT);
OnTime = on;
OffTime = off;
ledState = LOW;
previousMillis = 0;
}
void Update(unsigned long currentMillis)
{
if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Mark it as off
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin,ledState?HIGH:LOW);
//PORTA.OUTCLR = PIN2_bm; // turn off the output
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime) && ( OnTime > 0) )
{
ledState = HIGH; // mark it as on
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin,ledState?HIGH:LOW);
//PORTA.OUTSET = PIN2_bm; // turn on the output
}
}
void dutyCycle(long on,long off){
OnTime = on;
OffTime = off;
}
};