-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled_blink.cpp
93 lines (88 loc) · 2.09 KB
/
led_blink.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
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// Created by XINJIAWEI on 24-7-30.
//
#include "pico/stdlib.h"
/**
* led闪烁
* @param a
* @param b
* @param c
* @param d
* @param e
* @param once
*/
void blink(int a,int b, int c, int d, int e, bool once){
#ifndef PICO_DEFAULT_LED_PIN
#warning blink example requires a board with a regular LED
#else
if(a<= 0){
return;
}
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
int open_time = 500;
int close_time = 300;
int loop_wait_time = 2000;
bool loop = true;
while (loop) {
// 1
gpio_put(LED_PIN, true);
sleep_ms(open_time * a);
gpio_put(LED_PIN, false);
// 2
if(b * c * d * e != 0){
sleep_ms(close_time);
gpio_put(LED_PIN, true);
sleep_ms(open_time * b);
gpio_put(LED_PIN, false);
sleep_ms(close_time);
// 3
gpio_put(LED_PIN, true);
sleep_ms(open_time * c);
gpio_put(LED_PIN, false);
sleep_ms(close_time);
// 4
gpio_put(LED_PIN, true);
sleep_ms(open_time * d);
gpio_put(LED_PIN, false);
sleep_ms(close_time);
// 5
gpio_put(LED_PIN, true);
sleep_ms(open_time * e);
gpio_put(LED_PIN, false);
sleep_ms(loop_wait_time);
}else{
// 短暂闪烁不循环
loop = false;
}
if(once){
loop = false;
}
}
#endif
}
void uart_rx_blink(){
#ifndef PICO_DEFAULT_LED_PIN
#warning blink example requires a board with a regular LED
#else
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
int open_time = 150;
int close_time = 150;
// 1
int i = 1;
do{
gpio_put(LED_PIN, true);
sleep_ms(open_time);
gpio_put(LED_PIN, false);
sleep_ms(close_time);
i++;
} while (i > 3);
// 5
gpio_put(LED_PIN, true);
sleep_ms(open_time);
gpio_put(LED_PIN, false);
#endif
}