1801 views|2 replies

282

Posts

2

Resources
The OP
 

[RVB2601 Creative Application Development] 3. Onboard Button Experiment [Copy link]

 This post was last edited by hehung on 2022-3-6 13:07
  • Preface

The previous article explained how to use the official routines to operate RGB . This article will use the project in the previous article and add button control.

Purpose: When key1 is pressed , the red light is on; when key2 is pressed , the green light is on; when both key1 and key2 are pressed, the blue light is on; if no key is pressed, the RGB light is off.

  • Schematic

Let's first look at the schematic diagram of the buttons and LEDs .

The button schematic is as follows. The principle says K4 and K5 , which is inconsistent with the button names on the board. We look at the port multiplexing table to determine which button it is. The details will be explained below.

From the schematic diagram, after pressing the button, the GPIO port level will become low. If the button is not pressed, the GPIO port is 3.3V high level.

The port multiplexing table is shown below. It can be seen that PA11 is connected to KEY1 and PA12 is connected to KEY2.

As for the circuit diagram of LED , as shown below, if it is a normal IO control, if the LED GPIO is high level, the LED is off, if it is low level, the LED is on. The previous post has explained the circuit diagram connection of the LED on RGB , so I will not repeat it here, as follows.

Blue -- PA4 -- PWM4

Green -- PA25 -- PWM2

Red -- PA7 -- PWM7

Code Editing

  1. Modify RGB operation mode

In the previous RGB operation, RGB was operated using PWM . This article will use ordinary GPIO to operate. Open the app_config.h file and modify it as follows. The RGB is controlled by ordinary GPIO in the main function. I will not repeat it here.

  1. Initialize KEY

Initialize PA11 and PA12 as normal GPIO input ports.

static csi_gpio_pin_t key1;
static csi_gpio_pin_t key2;
static void key_init(void)
{
  csi_pin_set_mux(PA11, PIN_FUNC_GPIO);
  csi_pin_set_mux(PA12, PIN_FUNC_GPIO);
  csi_gpio_pin_init(&key1, PA11);
  csi_gpio_pin_dir(&key1, GPIO_DIRECTION_INPUT);
  csi_gpio_pin_init(&key2, PA12);
  csi_gpio_pin_dir(&key2, GPIO_DIRECTION_INPUT);
}

  1. Button control logic

The button control logic is as follows:

When key1 is pressed, the red light is on; when key2 is pressed , the green light is on; when both key1 and key2 are pressed, the blue light is on; if no key is pressed, the RGB light is off.

The code is implemented as follows:

static void key_Lgc(void)
{
//	printf("%d---%d\n",csi_gpio_pin_read(&key1), csi_gpio_pin_read(&key2));
	/* Key1 和 Key2都按下,蓝灯亮 */
	if(GPIO_PIN_LOW == csi_gpio_pin_read(&key1) && GPIO_PIN_LOW == csi_gpio_pin_read(&key2))
	{
		csi_gpio_pin_write(&r, GPIO_PIN_HIGH);
        csi_gpio_pin_write(&g, GPIO_PIN_HIGH);
        csi_gpio_pin_write(&b, GPIO_PIN_LOW);
	}
	/* Key1按下,红灯亮 */
	else if(GPIO_PIN_LOW == csi_gpio_pin_read(&key1))
	{
		csi_gpio_pin_write(&r, GPIO_PIN_LOW);
        csi_gpio_pin_write(&g, GPIO_PIN_HIGH);
        csi_gpio_pin_write(&b, GPIO_PIN_HIGH);
	}
	/* Key2按下,绿灯亮 */
	else if(GPIO_PIN_LOW == csi_gpio_pin_read(&key2))
	{
		csi_gpio_pin_write(&r, GPIO_PIN_HIGH);
        csi_gpio_pin_write(&g, GPIO_PIN_LOW);
        csi_gpio_pin_write(&b, GPIO_PIN_HIGH);
	}
	/* 都没按下,灭 */
	else
	{
		csi_gpio_pin_write(&r, GPIO_PIN_HIGH);
        csi_gpio_pin_write(&g, GPIO_PIN_HIGH);
        csi_gpio_pin_write(&b, GPIO_PIN_HIGH);
	}
}

  1. demo_task function modification

Add key_init() before the while loop to initialize the key-related GPIO .

In the while loop body, delete led_refresh , change the task cycle to 10ms , and put key_lgc () in the while body to determine whether the key is pressed and control the corresponding RGB light on and off.

static void demo_task(void *arg)
{
    lv_init();
    oled_init();
    lable_test();
    led_pinmux_init();
	key_init();

    while (1)
    {
        lv_task_handler();
        udelay(1000 * 10);
        lv_tick_inc(1);
//        led_refresh();
		key_Lgc();
    }
}
  • Effect Demonstration

The expected results are as follows:

Latest reply

Now I see that no one has replied to your post, so I’ll give you one. How is your project going recently?  Details Published on 2022-5-4 17:56
 
 

6841

Posts

11

Resources
2
 
Now I see that no one has replied to your post, so I’ll give you one. How is your project going recently?

Comments

Not finished yet  Details Published on 2022-5-6 09:25
 
 
 

282

Posts

2

Resources
3
 
lugl4313820 posted on 2022-5-4 17:56 Now I see that no one has replied to your post, so I will give you one. How is the recent project going?

Not finished yet

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
The Surrender of Bandits at Birdcage Mountain

Hu Ge's new work http://www.6rooms.com/nlsdwatch.php?v=2755 is really funny. Hu Ge almost went bankrupt to make this fil ...

Homemade STEVAL-IPM05F 3Sh board: FOC motor control 400V/8A non-sensing/sensing Hall/sensing encoder and other reference programs...

This post was last edited by music_586 on 2019-4-4 19:06 This content was originally created by EEWORLD forum user musi ...

Wuhan plague, the possibility of third, fourth, fifth and sixth generation infection cases

I heard that it has already appeared in the third and fourth generations. Does this mean that it has been transmitted se ...

CAN IAP Example

This content is originally created by EEWORLD forum user Xueshan Feihu11 . If you want to reprint or use it for comm ...

GPIO pin multiplexing in C6455

In addition, when using GPIO, you also need to consider the pin reuse of the corresponding chip. Taking 6455 as an examp ...

31 "Millions of Miles" Raspberry Pi Car——Ubuntu MATE System Installation

Next, I was going to start learning ROS, but it was particularly difficult to install it on the Raspberry Pi operating ...

[Sipeed LicheeRV 86 Panel Review] Developing RISCV Bare Metal Programming Using the Emerging Programming Language Rust

This post was last edited by mars4zhu on 2022-4-20 16:29 Developing RISCV bare metal programming using the emerging pro ...

【Tuya BK7231N】Unboxing Experience

Tuya IoT provides a series of simple and fast development platforms, providing a simple and easy development method for ...

CUK circuit combined with SEPIC circuit

Dear seniors: It feels like domestic power supply manufacturers are springing up like mushrooms after rain, but most of ...

There are really more and more digital people, and it is hard to tell the real from the fake

Some of Meituan’s live broadcasts now are all digital people, and they will also answer your questions. If you don’t l ...

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