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); }