-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblink.c
More file actions
58 lines (50 loc) · 1.06 KB
/
blink.c
File metadata and controls
58 lines (50 loc) · 1.06 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
57
58
/*
* File: blink.c
* Author: M71906
*
* Created on October 12, 2022, 4:47 PM
*/
#include <xc.h>
#include "mcc_generated_files/mcc.h"
#include "rtcounter.h"
#include "blink.h"
bool blinkEnable = false;
bool blinkState = false;
uint16_t blinkTime = 0;
#define BLINK_ON 100
#define BLINK_OFF 1000
bool isBlinkOn(void)
{
return blinkState;
}
void setBlinkState(bool newState)
{
blinkState = newState;
if(blinkState)
IO_PB7_SetLow();
else
IO_PB7_SetHigh();
}
void setBlinkEnable(bool enable)
{
blinkEnable = enable;
blinkTime = getMilliseconds() + BLINK_OFF;
}
void handleBlink(void)
{
if(!blinkEnable) return;
uint16_t currentMillis = getMilliseconds();
if(currentMillis == blinkTime)
{
if(isBlinkOn())
{
blinkTime = currentMillis + BLINK_OFF;
setBlinkState(false);
}
else
{
blinkTime = currentMillis + BLINK_ON;
setBlinkState(true);
}
}
}