-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (97 loc) · 3.16 KB
/
main.cpp
File metadata and controls
107 lines (97 loc) · 3.16 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "hal.h"
int num1 = 3;
int num2 = 8;
bool button = false;
int delay = 500;
bool sw[4] = {false, false, false, false};
unsigned int leds_num[7] = {GPIO_PIN_3, GPIO_PIN_4, GPIO_PIN_5,
GPIO_PIN_6, GPIO_PIN_5, GPIO_PIN_4, GPIO_PIN_3};
unsigned int leds_num2[7] = {GPIO_PIN_8, GPIO_PIN_9, GPIO_PIN_11,
GPIO_PIN_12, GPIO_PIN_11, GPIO_PIN_9, GPIO_PIN_8};
unsigned int sw_num[4] = {GPIO_PIN_4, GPIO_PIN_8, GPIO_PIN_10, GPIO_PIN_12};
void change_signal(int i){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);
switch(i){
case 0:
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
break;
case 1:
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
break;
case 2:
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
break;
}
}
void set_yellow(){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
}
bool check_button(){
GPIO_PinState state = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_15);
if(state == GPIO_PIN_RESET){
return true;
} else {
return false;
}
}
void lamp(){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_5, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_8, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_9, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
while(true){
change_signal(2);
button = check_button();
}
}
void anime(int i){
HAL_GPIO_WritePin(GPIOD, leds_num[i], GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, leds_num2[i], GPIO_PIN_SET);
HAL_Delay(delay);
HAL_GPIO_WritePin(GPIOD, leds_num[i], GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD, leds_num2[i], GPIO_PIN_RESET);
}
int umain(){
int i = 0;
while(1){
for(int j = 0; j<4; j++){
sw[j] = GPIO_PIN_SET==HAL_GPIO_ReadPin(GPIOE, sw_num[j]);
}
if(!sw[0] && !sw[1] && sw[2] && !sw[3]){
//for (int i = 0;i<=6;i++){
change_signal(0);
anime(i);
i++;
if (i == 6) {
i = 0;
}
if (check_button()) {
change_signal(1);
HAL_Delay(300);
while(1){
if (check_button()){
break;
}
}
}
//}
} else {
set_yellow();
for (int i = 0;i<4;i++){
if(sw[i]){
HAL_GPIO_WritePin(GPIOD, leds_num[i], GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(GPIOD, leds_num[i], GPIO_PIN_RESET);
}
}
}
}
return 0;
}