Since the Anxinke Bluetooth development board is a development board for Bluetooth applications, the onboard peripheral resources are relatively few, only two categories, namely: one is RGB_LED, and the other is 2 independent LEDs. The schematic diagram is shown in Figure 1.
Figure 1 LED circuit
With the schematic diagram above, you have the pin number to control the LED.
For some reason, since an example of the GPIO port is provided in the routine, why not light up an LED to give everyone some light?
Since there are none, let's light them up ourselves. If that's not enough, just light up a few more!
1. Turn on the warm light
The main program for lighting up the warm-colored lights is:
int app_main(void)
{
/* Initialize the operating system */
osal_init_system();
osal_pwrmgr_device( PWRMGR_BATTERY );
hal_gpio_pin_init(0, 1);
hal_gpio_write(0, 1);
/* Start OSAL */
osal_start_system(); // No Return from here
return 0;
}
After the program is downloaded, its execution effect is shown in Figure 2.
Figure 2: Light up the warm light
2. Turn on the cold and warm lights
Based on lighting the warm light, the procedure for lighting the warm and cold lights is as follows:
int app_main(void)
{
/* Initialize the operating system */
osal_init_system();
osal_pwrmgr_device( PWRMGR_BATTERY );
hal_gpio_pin_init(0, 1);
hal_gpio_write(0, 1);
hal_gpio_pin_init(P34, 1);
hal_gpio_write(P34, 1);
/* Start OSAL */
osal_start_system(); // No Return from here
return 0;
}
After the program is downloaded, its execution effect is shown in Figure 3.
Figure 3: Light up the cold and warm dual lights
3. Flashing effect
Since the LED can be lit, the project LED is not a problem. The LED flashing can be realized through delay processing. The program for LED flashing is:
int app_main(void)
{
/* Initialize the operating system */
osal_init_system();
osal_pwrmgr_device( PWRMGR_BATTERY );
hal_gpio_pin_init(P0, OEN);
hal_gpio_write(P0, 1);
hal_gpio_pin_init(P15, OEN);//R
hal_gpio_write(P15, 1);
hal_gpio_pin_init(P34, OEN);//B
hal_gpio_write(P34, 1);
while(1)
{
for(i=0;i<1000;i++)
for(j=0;j<2000;j++);
hal_gpio_write(P34, 1);
for(i=0;i<1000;i++)
for(j=0;j<2000;j++);
hal_gpio_write(P34, 0);
}
/* Start OSAL */
osal_start_system(); // No Return from here
return 0;
}
Of course, the delay statement can also be separated into an independent function, the content of which is:
void delay(int ms)
{
int i,j;
for(i=0;i<ms;i++)
for(j=0;j<2000;j++);
}
The main program using the delay function is:
int app_main(void)
{
/* Initialize the operating system */
osal_init_system();
osal_pwrmgr_device( PWRMGR_BATTERY );
hal_gpio_pin_init(P0, OEN);
hal_gpio_write(P0, 1);
hal_gpio_pin_init(P15, OEN);
hal_gpio_write(P15, 1);
hal_gpio_pin_init(P34, OEN);
hal_gpio_write(P34, 1);
while(1)
{
delay(1000);
hal_gpio_write(P34, 1);
delay(1000);
hal_gpio_write(P34, 0);
}
/* Start OSAL */
osal_start_system(); // No Return from here
return 0;
}
4. Light up all LEDs
In addition to the cold and warm LEDs, there is also an RGB_LED on board. The program to light up all the LEDs is:
int app_main(void)
{
/* Initialize the operating system */
osal_init_system();
osal_pwrmgr_device( PWRMGR_BATTERY );
hal_gpio_pin_init(P0, OEN);
hal_gpio_write(P0, 1);
hal_gpio_pin_init(P34, OEN);
hal_gpio_write(P34, 1);
hal_gpio_pin_init(P23, OEN);
hal_gpio_write(P23, 1);
hal_gpio_pin_init(P18, OEN);
hal_gpio_write(P18, 1);
hal_gpio_pin_init(P15, OEN);
hal_gpio_write(P15, 1);
while(1)
{
delay(1000);
hal_gpio_write(P34, 1);
delay(1000);
hal_gpio_write(P34, 0);
}
/* Start OSAL */
osal_start_system(); // No Return from here
return 0;
}
After the program is downloaded, its execution effect is shown in Figure 4.
Figure 4 Light up all LEDs
In addition, the external LED module can be lit up through the expansion interface, and the effect achieved is shown in Figure 5.
Figure 5 Lighting up the external LED module