-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlink_Led_1.c
56 lines (51 loc) · 881 Bytes
/
Blink_Led_1.c
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
#include <stdint.h>
#include <stdbool.h>
#define Blink_Time 500
#define Led_Pin 15
typedef enum
{
Reset = 0,
Check_Times,
Check_Led_State,
Turn_On_Led,
Turn_Off_Led
} STATE;
uint64_t t0, t1;
bool Led_State;
STATE state;
void setup()
{
pinMode(Led_Pin, OUTPUT);
state = Reset;
digitalWrite(Led_Pin, HIGH);
}
void loop()
{
switch (state)
{
case Reset:
t0 = millis();
state = Check_Times;
break;
case Check_Times:
t1 = millis();
if ((t1 - t0) > Blink_Time)
state = Check_Led_State;
break;
case Check_Led_State:
Led_State = digitalRead(Led_Pin);
if (Led_State == HIGH)
state = Turn_Off_Led;
else
state = Turn_On_Led;
break;
case Turn_On_Led:
digitalWrite(Led_Pin, HIGH);
state = Reset;
break;
case Turn_Off_Led:
digitalWrite(Led_Pin, LOW);
state = Reset;
break;
}
}