From 7e669bc8dac3c0528ee891814f49f149e2733ecf Mon Sep 17 00:00:00 2001 From: james <1943357252@qq.com> Date: Thu, 25 Jul 2024 01:18:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BF=A1=E5=8F=B7=E9=87=8F?= =?UTF-8?q?=EF=BC=8C=E5=B0=86=E7=81=AF=E7=9A=84=E6=93=8D=E4=BD=9C=E6=94=BE?= =?UTF-8?q?=E5=9B=9E=E7=81=AF=E7=9A=84=E7=BA=BF=E7=A8=8B=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Day3/README.md | 15 ++++++++++++--- applications/main.c | 19 +++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Day3/README.md b/Day3/README.md index 50a90be..ab9a182 100644 --- a/Day3/README.md +++ b/Day3/README.md @@ -181,7 +181,16 @@ dist 的好处 pkgs --update ``` -## 示例点灯 +## 示例灭灯 ### 灭了怎么点都不亮 -在key线程循环中每次点亮? -因为按键按灭就没再点亮 \ No newline at end of file +因为按键按灭就没再点亮 +在key线程循环开始每次点亮? +### 灯轻微闪烁,几乎看不出 +不能及时获取?用无等待获取信号量? +### 还是一样…… +因为采用了延时防止误触,判断是否按下按键花了一点时间 +~~只要知道按键没有按下就亮灯就行~~ +在下次判断按键没按下之后再亮灯 +### 居然在按键的线程在控制led +改为没摁才释放信号量,led线程获取到后设为亮灯 +并在获取信号量前将led设为灭灯 diff --git a/applications/main.c b/applications/main.c index a8eac1d..f4b27b6 100644 --- a/applications/main.c +++ b/applications/main.c @@ -79,23 +79,22 @@ static void key_name_entry(void *parameter) rt_uint32_t count=0; while (1) { - if(rt_pin_read(PIN_KEY0) == PIN_LOW) { rt_thread_mdelay(100); if(rt_pin_read(PIN_KEY0) == PIN_LOW) { - rt_kprintf("key0 is pressed (%d)\r", count++); - rt_sem_release(dynamic_sem); + rt_kprintf("key0 is pressed (%d) ", count++); + // rt_sem_release(dynamic_sem); } else { - rt_pin_write(GPIO_LED_R, PIN_LOW); + rt_sem_release(dynamic_sem); } } else { - rt_pin_write(GPIO_LED_R, PIN_LOW); + rt_sem_release(dynamic_sem); } rt_thread_mdelay(10); } @@ -108,15 +107,11 @@ static void led_name_entry(void *parameter) rt_uint32_t result=0; while (1) { + rt_pin_write(GPIO_LED_R, PIN_HIGH); result = rt_sem_take(dynamic_sem, RT_WAITING_FOREVER); if (result == RT_EOK) - { - rt_kprintf("LED HIGH\n"); - rt_pin_write(GPIO_LED_R, PIN_HIGH); - } - else - { - rt_kprintf("LED LOW"); + { + // rt_kprintf("LED LOW\n"); rt_pin_write(GPIO_LED_R, PIN_LOW); }