RT-GasFlowMeter/applications/LED/LED.c

77 lines
1.8 KiB
C

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2025-07-21 Administrator the first version
*/
#include "led.h"
#include <rtdevice.h>
#include <rtthread.h>
#include <board.h>
#define LED_PIN GET_PIN(B, 0) // RT-Thread 的 PIN 宏
#define LED_PIN1 GET_PIN(B, 1) // RT-Thread 的 PIN 宏
#define LED_PIN2 GET_PIN(B, 2) // RT-Thread 的 PIN 宏
static rt_thread_t led_thread = RT_NULL;
/* LED 线程入口函数 */
static void led_thread_entry(void *parameter)
{
rt_uint8_t led_state = 0;
/* 设置引脚为输出模式 */
rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(LED_PIN1, PIN_MODE_OUTPUT);
rt_pin_mode(LED_PIN2, PIN_MODE_OUTPUT);
while (1)
{
/* 切换 LED 状态 */
led_state = !led_state;
rt_pin_write(LED_PIN, led_state);
rt_pin_write(LED_PIN1, led_state);
rt_pin_write(LED_PIN2, led_state);
rt_thread_mdelay(200);
rt_pin_write(LED_PIN, led_state);
rt_pin_write(LED_PIN1, led_state);
rt_pin_write(LED_PIN2, !led_state);
rt_thread_mdelay(200);
rt_pin_write(LED_PIN, led_state);
rt_pin_write(LED_PIN1, !led_state);
rt_pin_write(LED_PIN2, !led_state);
rt_thread_mdelay(200);
rt_kprintf("meter: %d\n", led_state);
}
}
int controlLED(){
/* 创建线程 */
led_thread = rt_thread_create(
"led",
led_thread_entry,
RT_NULL,
512,
RT_THREAD_PRIORITY_MAX / 2,
20);
/* 启动线程 */
if (led_thread != RT_NULL)
{
rt_thread_startup(led_thread);
return RT_EOK;
}
else
{
return -RT_ERROR;
}
}