-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadiationIndicator.cpp
More file actions
56 lines (50 loc) · 1.3 KB
/
RadiationIndicator.cpp
File metadata and controls
56 lines (50 loc) · 1.3 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
/** Class for a Radiation Indicator LED
* on the robot for signaling radiation.
**/
#include "RadiationIndicator.h"
/** Constructor
* @param pin Pin for the LED
* @param period Total period of the blink patter
**/
RadiationIndicator::RadiationIndicator(int pin, int period) : _ledPin(pin), _period(period) {
_onTime = period/8;
shouldBlink = false;
}
/** Initialize the LED, and set the output
* High so that it can be verified that it
* is plugged in.
**/
void RadiationIndicator::initialize() {
pinMode(_ledPin, OUTPUT);
digitalWrite(_ledPin, HIGH);
}
/** Updates the current state of the LED
* based on the time, and if it should be
* blinking. Does a fancy heartbeat blink!
**/
void RadiationIndicator::update() {
//Check if the light should be blinking
if(shouldBlink) {
//Get the current time in the period
long periodIime = millis() % _period;
//Blink in a heartbeat like pattern
if((periodIime < _onTime) ||
((periodIime > 2*_onTime) && (periodIime < 3*_onTime))) {
digitalWrite(_ledPin, HIGH);
} else {
digitalWrite(_ledPin, LOW);
}
} else {
digitalWrite(_ledPin, LOW);
}
}
/** Set the LED to blink
**/
void RadiationIndicator::setBlink() {
shouldBlink = true;
}
/** Set the LED to not blink
**/
void RadiationIndicator::setNotBlink() {
shouldBlink = false;
}