ART-Pi入门篇——(四)LED闪烁

点灯代码程序编写

新建工程可以在系列文章软件篇中找到。

新建出来的项目,自带一个点灯代码示例。例程主要功能是让板载的 RGB-LED 中的蓝色 LED 不间断闪烁。

在这里插入图片描述
在这里插入图片描述

在 main 函数中,将该引脚配置为输出模式,并在下面的 while 循
如上图所示,RGB-LED 属于共阳 LED, 阴极 分别与单片机的引脚相连,其中蓝色 LED 对应 PI8 引脚。单片机引脚输出低电平即可点亮 LED,输出高电平则会熄灭 LED。

1.使用 #define LED_PIN_Blue GET_PIN(I, 8)定义LED对应的IO口。
2.使用rt_pin_mode(LED_PIN_Blue, PIN_MODE_OUTPUT);配置输出模式。
3.使用rt_pin_write(LED_PIN_Blue, PIN_HIGH);控制IO口输出电平。
4.使用rt_thread_mdelay(500);进行ms级延时。

Main.c


/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-09-02     RT-Thread    first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include "drv_common.h"

#define LED_PIN_Blue GET_PIN(I, 8)
#define LED_PIN_Red GET_PIN(C, 15)

int main(void)
{
    rt_uint32_t count = 1;

    rt_pin_mode(LED_PIN_Blue, PIN_MODE_OUTPUT);//蓝灯IO口配置为输出
    rt_pin_mode(LED_PIN_Red, PIN_MODE_OUTPUT);//红灯IO口配置为输出

    while(count++)
    {
        rt_thread_mdelay(500); //红亮蓝灭
        rt_pin_write(LED_PIN_Blue, PIN_HIGH);
        rt_pin_write(LED_PIN_Red, PIN_LOW);
        rt_thread_mdelay(500);//红灭蓝亮
        rt_pin_write(LED_PIN_Blue, PIN_LOW);
        rt_pin_write(LED_PIN_Red, PIN_HIGH);
        rt_thread_mdelay(500);//红亮蓝亮
        rt_pin_write(LED_PIN_Blue, PIN_LOW);
        rt_pin_write(LED_PIN_Red, PIN_LOW);
        rt_thread_mdelay(500);//红灭蓝灭
        rt_pin_write(LED_PIN_Blue, PIN_HIGH);
        rt_pin_write(LED_PIN_Red, PIN_HIGH);
    }
    return RT_EOK;
}

#include "stm32h7xx.h"
static int vtor_config(void)
{
    /* Vector Table Relocation in Internal QSPI_FLASH */
    SCB->VTOR = QSPI_BASE;
    return 0;
}
INIT_BOARD_EXPORT(vtor_config);



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值