调整信号量,将灯的操作放回灯的线程中
This commit is contained in:
parent
da6779f796
commit
7e669bc8da
|
@ -181,7 +181,16 @@ dist 的好处
|
|||
pkgs --update
|
||||
```
|
||||
|
||||
## 示例点灯
|
||||
## 示例灭灯
|
||||
### 灭了怎么点都不亮
|
||||
在key线程循环中每次点亮?
|
||||
因为按键按灭就没再点亮
|
||||
因为按键按灭就没再点亮
|
||||
在key线程循环开始每次点亮?
|
||||
### 灯轻微闪烁,几乎看不出
|
||||
不能及时获取?用无等待获取信号量?
|
||||
### 还是一样……
|
||||
因为采用了延时防止误触,判断是否按下按键花了一点时间
|
||||
~~只要知道按键没有按下就亮灯就行~~
|
||||
在下次判断按键没按下之后再亮灯
|
||||
### 居然在按键的线程在控制led
|
||||
改为没摁才释放信号量,led线程获取到后设为亮灯
|
||||
并在获取信号量前将led设为灭灯
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue