3177 views|5 replies

1452

Posts

1

Resources
The OP
 

[AB32VG1 Development Board Review] RGB_LED Color Change Display [Copy link]

 

The AB32VG1 development board has an RGB_LED on board, and its schematic diagram is shown in Figure 1.

Figure 1 RGB_LED circuit connection

According to the principle of color superposition, yellow, bright blue, pink and white can be combined.

The procedure to achieve the color change effect 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);
 rt_pin_write(pin, PIN_HIGH);
 rt_pin_write(pin1, PIN_HIGH);
 rt_pin_write(pin2, PIN_HIGH);
 while (1)
 {
 if(cnt % 8 == 0)
 {
 rt_pin_write(pin, PIN_LOW);
 rt_pin_write(pin1, PIN_HIGH);
 rt_pin_write(pin2, PIN_HIGH);
 }
 if(cnt % 8 == 1)
 {
 rt_pin_write(pin, PIN_HIGH);
 rt_pin_write(pin1, PIN_LOW);
 rt_pin_write(pin2, PIN_HIGH);
 }
 if(cnt % 8 == 2)
 {
 rt_pin_write(pin, PIN_HIGH);
 rt_pin_write(pin1, PIN_HIGH);
 rt_pin_write(pin2, PIN_LOW);
 }
 if(cnt % 8 == 3)
 {
 rt_pin_write(pin, PIN_LOW);
 rt_pin_write(pin1, PIN_LOW);
 rt_pin_write(pin2, PIN_HIGH);
 }
 if(cnt % 8 == 4)
 {
 rt_pin_write(pin, PIN_HIGH);
 rt_pin_write(pin1, PIN_LOW);
 rt_pin_write(pin2, PIN_LOW);
 }
 if(cnt % 8 == 5)
 {
 rt_pin_write(pin, PIN_LOW);
 rt_pin_write(pin1, PIN_HIGH);
 rt_pin_write(pin2, PIN_LOW);
 }
 if(cnt % 8 == 6)
 {
 rt_pin_write(pin, PIN_LOW);
 rt_pin_write(pin1, PIN_LOW);
 rt_pin_write(pin2, PIN_LOW);
 }
 if(cnt % 8 == 7)
 {
 rt_pin_write(pin, PIN_HIGH);
 rt_pin_write(pin1, PIN_HIGH);
 rt_pin_write(pin2, PIN_HIGH);
 }
 cnt++;
 rt_thread_mdelay(1000);
 }
 return 0;
}

Figure 2 Demonstration effect diagram

This post is from Domestic Chip Exchange

Latest reply

Why don't we put three adjacent pins for better control?   Details Published on 2021-8-12 17:15
 
 

1w

Posts

25

Resources
2
 

The effect is good. I feel that the program can be optimized. Instead of writing 8 if statements, the LED status can be set according to each binary bit of cnt, so only 3 if statements are needed.

This post is from Domestic Chip Exchange

Comments

Makes sense!  Details Published on 2021-8-12 14:28
Makes sense!  Details Published on 2021-8-12 11:50
 
 
 

1412

Posts

3

Resources
3
 
The effect is good. I feel that the program can be optimized. Instead of writing 8 if statements, the LED state can be set according to each binary bit of cnt, so only 3 if statements are needed.
Makes sense!
This post is from Domestic Chip Exchange
 
 
 

1452

Posts

1

Resources
4
 
dcexpert posted on 2021-8-12 09:37 The effect is good. I feel that the program can be optimized. Instead of writing 8 if statements, the LED status can be set according to each binary bit of cnt. In this way, only 3 if statements are needed...

Makes sense, I'll try it again.

This post is from Domestic Chip Exchange
 
 
 

7422

Posts

2

Resources
5
 

Why don't we put three adjacent pins for better control?

This post is from Domestic Chip Exchange

Comments

It's hard to say. I think it may be related to the design of the Arduino interface. PE1 and PE4 are on the same side of the chip, but they are separated from CLK and SDA. PA1 may be the result of the pin allocation according to the Arduino interface to keep these three pins as PWM pins. I think there are such factors.  Details Published on 2021-8-12 18:21
Personal signature

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

 
 
 

1452

Posts

1

Resources
6
 
freebsder posted on 2021-8-12 17:15 Why don't we put three adjacent pins for better control?

It's hard to say. I think it may be related to the design of the Arduino interface. PE1 and PE4 are on the same side of the chip, but they are separated from CLK and SDA. PA1 may be the result of the pin allocation according to the Arduino interface to keep these three pins as PWM pins. My analysis may not be accurate.

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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