-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLed.cpp
80 lines (69 loc) · 1.41 KB
/
Led.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @file Led.cpp
*
* @brief Led clas
*
* This file implements the Led class
*
* @author Bryan Cisneros
*/
#include "Led.h"
#include "LedInterface.h"
#include <stdio.h>
#define FLASH_TIMEOUT (150)
Led::Led(int channel)
{
this->channel = channel;
count = 0;
// initialize to off and not flashing
flashing = false;
led_on = false;
}
Led::~Led(void)
{
}
void Led::tick(void)
{
// If the LED is flashing, increment the counter. If the timeout is reached,
// toggle the LED and reset the counter
if (flashing)
{
count++;
if (count >= FLASH_TIMEOUT)
{
if (led_on)
{
LedInterface_turnOffLed(channel);
led_on = false;
}
else
{
LedInterface_turnOnLed(channel);
led_on = true;
}
count = 0;
}
}
}
void Led::turnOn(void)
{
// Turn on the LED, and update internal status variables
LedInterface_turnOnLed(channel);
led_on = true;
flashing = false;
}
void Led::turnOff(void)
{
// Turn off the LED, and update internal status variables
LedInterface_turnOffLed(channel);
led_on = false;
flashing = false;
}
void Led::flash(void)
{
// Start with the LED on, and update internal status variables
LedInterface_turnOnLed(channel);
led_on = true;
flashing = true;
count = 0;
}