【AB32VG1开发板测评】按键控制LED及风扇
本帖最后由 jinglixixi 于 2021-8-21 00:45 编辑<p class="paragraph" style="margin-top:4px; margin-bottom:4px">在AB32VG1开发板上,配有LED和KEY,其原理图如图1所示。</p>
<p> </p>
<p> </p>
<p>图1 LED与KEY 线路连接</p>
<p> </p>
<p>以KEY控制LED的程序如下:</p>
<pre>
<code class="language-cpp">int main(void)
{
uint32_t cnt = 0;
uint8_t pin = rt_pin_get("PE.1");
rt_pin_mode(pin, PIN_MODE_OUTPUT);
uint8_t pin1 = rt_pin_get("PE.4");
rt_pin_mode(pin1, PIN_MODE_OUTPUT);
uint8_t pin2 = rt_pin_get("PA.1");
rt_pin_mode(pin2, PIN_MODE_OUTPUT);
uint8_t S2 = rt_pin_get("PF.1");
rt_pin_mode(S2, PIN_MODE_INPUT_PULLUP );
uint8_t S3 = rt_pin_get("PF.0");
rt_pin_mode(S3, PIN_MODE_INPUT_PULLUP );
uint8_t S4 = rt_pin_get("PA.2");
rt_pin_mode(S4, PIN_MODE_INPUT_PULLUP );
rt_pin_write(pin, PIN_HIGH);
rt_pin_write(pin1, PIN_HIGH);
rt_pin_write(pin2, PIN_HIGH);
while (1)
{
if(rt_pin_read(S2)==PIN_LOW) {
rt_pin_write(pin, PIN_LOW);
} else {
rt_pin_write(pin, PIN_HIGH);
}
if(rt_pin_read(S3)==PIN_LOW) {
rt_pin_write(pin1, PIN_LOW);
} else {
rt_pin_write(pin1, PIN_HIGH);
}
if(rt_pin_read(S4)==PIN_LOW) {
rt_pin_write(pin2, PIN_LOW);
} else {
rt_pin_write(pin2, PIN_HIGH);
}
}
}</code></pre>
<p>该程序的作用是以按键S2~S4分别控制LED_R、LED_G及LED_B的亮灭。</p>
<p> </p>
<p>在开发板上配有Arduino接口,利用它可以控制外挂的LED模块,在控制引脚连接PA0的情况下,其控制程序如下:</p>
<pre>
<code class="language-cpp">#include <rtthread.h>
#include "board.h"
int main(void)
{
uint32_t cnt = 0;
uint8_t pin0 = rt_pin_get("PA.0");
rt_pin_mode(pin0, PIN_MODE_OUTPUT);
while (1)
{
if (cnt % 2 == 0) {
rt_pin_write(pin0, PIN_LOW);
} else {
rt_pin_write(pin0, PIN_HIGH);
}
cnt++;
rt_thread_mdelay(500);
}
return 0;
}</code></pre>
<p> </p>
<p> </p>
<p>图2 驱动LED模块</p>
<p> </p>
<p>此外,若将LED模块换为风扇模块则可控制风扇的运转,并可以延时值来调节风扇转速。</p>
<p> </p>
<p>图3 驱动风扇模块</p>
<p>下边是通过延时调节I/O模拟 PWM的占空比?</p> littleshrimp 发表于 2021-8-21 08:07
下边是通过延时调节I/O模拟 PWM的占空比?
<p>看错了 好像是通过延时调节频率</p> littleshrimp 发表于 2021-8-21 08:07
下边是通过延时调节I/O模拟 PWM的占空比?
<p>道理相近</p>
<p>了解更多智能硬件相关产品~请戳:【华为开发者联盟生态市场智能硬件专区https://developer.huawei.com/consumer/cn/market/prod-list?categoryIdL1=7e857be8d4b24a7e97ddf5d941b38ca1&ha_source=mkt-thirdforum】</p>
<p>看来楼主买了不少模块啊</p>
freebsder 发表于 2021-8-23 17:13
看来楼主买了不少模块啊
<p>哈哈!</p>
<p>调低占空比,终于可以不晃眼了!</p>
<p>470R的电阻,灯太亮</p>
页:
[1]