点灯程序
要求:在FinSH控制台输入led 1/2/3 on/off 命令来控制stm32f407板子上的三盏LED灯暗灭
#include <rtthread.h>
#include <dfs_posix.h>
#include <board.h>
#define LED1_PIN GET_PIN(C, 3)
#define LED2_PIN GET_PIN(A, 5)
#define LED3_PIN GET_PIN(A, 6)
static void led(int argc, char**argv)
{
if (argc < 3)
{
rt_kprintf("Please input'led <1 off|1 on |2 off|2 on|3 off|3 on>'\n");
return;
}
if (!rt_strcmp(argv[1], "1"))
{
if (!rt_strcmp(argv[2], "off"))
rt_pin_write(LED1_PIN, PIN_LOW);
else if (!rt_strcmp(argv[2], "on"))
rt_pin_write(LED1_PIN, PIN_HIGH);
else
rt_kprintf("Please input'led <1 off|1 on |2 off|2 on|3 off|3 on>'\n");
}
else if (!rt_strcmp(argv[1], "2"))
{
if (!rt_strcmp(argv[2], "off"))
rt_pin_write(LED2_PIN, PIN_LOW);
else if (!rt_strcmp(argv[2], "on"))
rt_pin_write(LED2_PIN, PIN_HIGH);
else
rt_kprintf("Please input'led <1 off|1 on |2 off|2 on|3 off|3 on>'\n");
}
else if (!rt_strcmp(argv[1], "3"))
{
if (!rt_strcmp(argv[2], "off"))
rt_pin_write(LED3_PIN, PIN_LOW);
else if (!rt_strcmp(argv[2], "on"))
rt_pin_write(LED3_PIN, PIN_HIGH);
else
rt_kprintf("Please input'led <1 off|1 on |2 off|2 on|3 off|3 on>'\n");
}
else
{
rt_kprintf("Please input'led <1 off|1 on |2 off|2 on|3 off|3 on>'\n");
}
}
MSH_CMD_EXPORT(led, led sample: led <1 off|1 on |2 off|2 on|3 off|3 on>);
|