-
Notifications
You must be signed in to change notification settings - Fork 10
/
blinker.cpp
executable file
·50 lines (31 loc) · 1.04 KB
/
blinker.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
#include <Arduino.h>
#include <blinker.h>
blinker::blinker(int inPin,float inOnMs, float inPeriodMs,boolean inInverse)
: squareWave(inPeriodMs,inOnMs) {
init = false;
pin = inPin;
inverse = inInverse;
}
blinker::~blinker(void) { }
// What to do when the pulse comes on..
void blinker::pulseOn(void) {
if (inverse) digitalWrite(pin,LOW);
else digitalWrite(pin,HIGH);
}
// What to do when the pulse is over..
void blinker::pulseOff(void) {
if (inverse) digitalWrite(pin,HIGH);
else digitalWrite(pin,LOW);
}
// This is your on/off switch. Call with a boolean tru=on false=off.
// The object is created in the "off" mode.
void blinker::setOnOff(bool onOff) {
if (!init) { // Not intialized?
pinMode(pin, OUTPUT); // Now you are!
init = true; // Note it.
}
if(onOff!=running()) { // Ignore if no change.
squareWave::setOnOff(onOff);
}
}
bool blinker::blinking(void) { return running(); }