2353 views|7 replies

1452

Posts

1

Resources
The OP
 

[AB32VG1 Development Board Review] Button Control LED and Fan [Copy link]

 This post was last edited by jinglixixi on 2021-8-21 00:45

The AB32VG1 development board is equipped with LED and KEY, and its schematic diagram is shown in Figure 1.

Figure 1 LED and KEY circuit connection

The procedure to control LED with KEY is as follows:

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);
 }
 }
}

The function of this program is to use buttons S2~S4 to control the on and off of LED_R, LED_G and LED_B respectively.

The development board is equipped with an Arduino interface, which can be used to control the external LED module. When the control pin is connected to PA0, the control program is as follows:

#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;
}

Figure 2 Driving LED module

In addition, if the LED module is replaced with a fan module, the operation of the fan can be controlled, and the fan speed can be adjusted by the delay value.

Figure 3 Driving fan module

This post is from Domestic Chip Exchange

Latest reply

By lowering the duty cycle, the glare is finally gone! 470R resistor, the light is too bright   Details Published on 2021-8-24 00:33
 
 

9702

Posts

24

Resources
2
 

Below is the duty cycle of I/O analog PWM adjusted by delay?

This post is from Domestic Chip Exchange

Comments

I misread it. It seems that the frequency is adjusted by delay.  Details Published on 2021-8-21 10:11
I misread it. It seems that the frequency is adjusted by delay.  Details Published on 2021-8-21 08:09
 
 
 

9702

Posts

24

Resources
3
 
littleshrimp posted on 2021-8-21 08:07 The following is how to adjust the duty cycle of I/O analog PWM through delay?

I misread it. It seems that the frequency is adjusted by delay.

This post is from Domestic Chip Exchange
 
 
 

1452

Posts

1

Resources
4
 
littleshrimp posted on 2021-8-21 08:07 Below is how to adjust the duty cycle of I/O analog PWM through delay?

Similar reasoning

This post is from Domestic Chip Exchange
 
 
 

3

Posts

0

Resources
5
 

To learn more about smart hardware related products, please click: [Huawei Developer Alliance Ecosystem Market Smart Hardware Zone https://developer.huawei.com/consumer/cn/market/prod-list?categoryIdL1=7e857be8d4b24a7e97ddf5d941b38ca1&ha_source=mkt-thirdforum]

This post is from Domestic Chip Exchange
 
 
 

7422

Posts

2

Resources
6
 

It seems that the OP bought a lot of modules.

This post is from Domestic Chip Exchange

Comments

Ha ha!  Details Published on 2021-8-24 00:21
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1452

Posts

1

Resources
7
 
freebsder posted on 2021-8-23 17:13 It seems that the OP bought a lot of modules

Ha ha!

This post is from Domestic Chip Exchange
 
 
 

37

Posts

0

Resources
8
 

By lowering the duty cycle, the glare is finally gone!

470R resistor, the light is too bright

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list