Contributed by WangChong, organized by Ai-Thinker
Test and Light Up an LED with the AI-WB2 Module
After successfully setting up the development environment, let's write a HelloWorld to verify the peripheral resources. Here we will try to light up 1 RGB LED. This tutorial is based on the Ai-WB2-32S-Kit development board. If you are using the Ai-WB2 chip, simply modify the GPIO ports yourself. The steps are as follows: 1- First, download the schematic of the AI-WB2-32S Kit from the official website. 2- As shown in the figure below, you only need to drive the corresponding ports IO3, IO14, and IO17 to a high level respectively, and the different LED colors will be lit up. 
3- The code is as follows:
Click to expand full code
#include <stdio.h>
#include <string.h>
//引入博流的GPIO库
#include "bl_gpio.h"
#include <FreeRTOS.h>
#include <task.h>
// define the gpio port for blue 定义蓝色gpio端口
#define BLUE_LED 3
// define the gpio port for red 定义红色gpio端口
#define RED_LED 14
// define the gpio port for green 定义绿色gpio端口
#define GREEN_LED 17
void main(){
// 允许端口输出
bl_gpio_enable_output(BLUE_LED,1,0);
//输出高电平
bl_gpio_output_set(BLUE_LED, 1);
//休眠一秒
vTaskDelay(1000);
bl_gpio_output_set(BLUE_LED, 0);
vTaskDelay(1000);
bl_gpio_enable_output(RED_LED,1,0);
bl_gpio_output_set(RED_LED, 1);
vTaskDelay(1000);
bl_gpio_output_set(RED_LED, 0);
vTaskDelay(1000);
bl_gpio_enable_output(GREEN_LED,1,0);
bl_gpio_output_set(GREEN_LED, 1);
vTaskDelay(1000);
bl_gpio_output_set(GREEN_LED, 0);
vTaskDelay(1000);
bl_gpio_output_set(BLUE_LED, 1);
bl_gpio_output_set(RED_LED, 1);
bl_gpio_output_set(GREEN_LED, 1);
}In the code above, I didn't really want to use FreeRTOS, but I don't know how to write a precise timer based on the current MCU. So, in order to use the vTaskDelay function from Task, I had to include FreeRTOS as a prerequisite dependency (since I haven't systematically studied FreeRTOS — learning must be done step by step, and you can't rush it).
Click to expand full code
**实验现象如下**
**蓝色灯亮起 - > 熄灭**
**红色灯亮起- > 熄灭**
**绿色灯亮起-> 熄灭**
**红绿蓝同时亮起**
Ps: The use of HAL functions or similar library functions greatly reduces the difficulty of application development. You don't really need to learn registers — you just need to master the functions.

