In the previous guide (here), we took a look how to configure the service to accept data from the smartphone to control single LED.
In this guide, we shall extend the service to accept multiple data to control multiple LEDs.
In this guide, we shall cover the following:
- Service modification.
- LED control.
- Results.
1. Service Modification
Continue from the previous guide, Open the ioc file within STM32CubeIDE project.
From STM32_WPAN, select the LEDControl Service, set the Value length to 2 and keep the rest of the settings from the pervious guide.
Save the project and this will generate the project.
2. LED Control:
Now, open custom_stm.c source file as following:
In the line:
/* USER CODE BEGIN CUSTOM_STM_Service_1_Char_1_ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE */
Add the following to control the LEDs as following:
uint8_t LED_Number=attribute_modified->Attr_Data[0]; uint8_t state=attribute_modified->Attr_Data[1]; switch (LED_Number) { case 0: HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, state); break; case 1: HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, state);break; case 2: HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, state);break; default:break; }
Thats all for the LED control.
Save the project, build the project and run it on your STM32WB55-Nucleo.
3. Results:
Using LightBlue, connect to the WB55_EExp:
Happy coding 😉
Add Comment