#include "stm32f4xx_hal.h"
// Define RGB LED pins
#define RED_PIN GPIO_PIN_0 // Example GPIO pin for the red LED
#define GREEN_PIN GPIO_PIN_1 // Example GPIO pin for the green LED
#define BLUE_PIN GPIO_PIN_2 // Example GPIO pin for the blue LED
#define RGB_PORT GPIOA // Example GPIO port
// Function to initialize GPIO pins
void GPIO_Init(void) {
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = RED_PIN | GREEN_PIN | BLUE_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(RGB_PORT, &GPIO_InitStruct);
}
int main(void) {
// Initialize the HAL Library
HAL_Init();
// Configure the system clock (if needed)
SystemClock_Config();
// Initialize GPIO pins
GPIO_Init();
while (1) {
// Turn on the red LED, turn off others
HAL_GPIO_WritePin(RGB_PORT, RED_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(RGB_PORT, GREEN_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RGB_PORT, BLUE_PIN, GPIO_PIN_RESET);
HAL_Delay(500); // Delay for 500 ms
// Turn on the green LED, turn off others
HAL_GPIO_WritePin(RGB_PORT, RED_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RGB_PORT, GREEN_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(RGB_PORT, BLUE_PIN, GPIO_PIN_RESET);
HAL_Delay(500); // Delay for 500 ms
// Turn on the blue LED, turn off others
HAL_GPIO_WritePin(RGB_PORT, RED_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RGB_PORT, GREEN_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RGB_PORT, BLUE_PIN, GPIO_PIN_SET);
HAL_Delay(500); // Delay for 500 ms
// Turn off all LEDs
HAL_GPIO_WritePin(RGB_PORT, RED_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RGB_PORT, GREEN_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(RGB_PORT, BLUE_PIN, GPIO_PIN_RESET);
HAL_Delay(500); // Delay for 500 ms
}
}