From aaa053fa8b7b4443072205366b38f03809b4033f Mon Sep 17 00:00:00 2001 From: Johnny Hsu Date: Wed, 13 Nov 2024 01:10:52 +0100 Subject: [PATCH] change led blinking behaviour --- Software/Core/Src/led.c | 29 ++++++++++++++++++----------- Software/Core/Src/main.c | 1 - 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Software/Core/Src/led.c b/Software/Core/Src/led.c index 8590082..d1910f7 100644 --- a/Software/Core/Src/led.c +++ b/Software/Core/Src/led.c @@ -5,6 +5,10 @@ #include "stm32f0xx_hal.h" #include "stm32f0xx_hal_tim.h" +#define DELAY 50000 + +int Counter = 0; + void led_init(TIM_HandleTypeDef* htim) { HAL_TIM_PWM_Start(htim, TIM_CHANNEL_1); HAL_TIM_PWM_Start(htim, TIM_CHANNEL_2); @@ -23,6 +27,11 @@ void led_init(TIM_HandleTypeDef* htim) { } void blink(TIM_HandleTypeDef* htim, int32_t color) { + if(Counter < DELAY) { + Counter ++; + } else { + Counter = 0; + } int32_t Blue = color & 0x000000FF; int32_t Green = (color & 0x0000FF00) >> 8; int32_t Red = (color & 0x00FF0000) >> 16; @@ -31,15 +40,13 @@ void blink(TIM_HandleTypeDef* htim, int32_t color) { TIM2->CCR2 = Red; TIM2->CCR3 = Blue; - HAL_TIM_PWM_Stop(htim, TIM_CHANNEL_1); - HAL_TIM_PWM_Stop(htim, TIM_CHANNEL_2); - HAL_TIM_PWM_Stop(htim, TIM_CHANNEL_3); - - HAL_Delay(500); - - HAL_TIM_PWM_Start(htim, TIM_CHANNEL_1); - HAL_TIM_PWM_Start(htim, TIM_CHANNEL_2); - HAL_TIM_PWM_Start(htim, TIM_CHANNEL_3); - - HAL_Delay(500); + if (Counter < DELAY/2) { + HAL_TIM_PWM_Stop(htim, TIM_CHANNEL_1); + HAL_TIM_PWM_Stop(htim, TIM_CHANNEL_2); + HAL_TIM_PWM_Stop(htim, TIM_CHANNEL_3); + } else { + HAL_TIM_PWM_Start(htim, TIM_CHANNEL_1); + HAL_TIM_PWM_Start(htim, TIM_CHANNEL_2); + HAL_TIM_PWM_Start(htim, TIM_CHANNEL_3); + } } \ No newline at end of file diff --git a/Software/Core/Src/main.c b/Software/Core/Src/main.c index 09baaee..db32e9c 100644 --- a/Software/Core/Src/main.c +++ b/Software/Core/Src/main.c @@ -24,7 +24,6 @@ #include "adc.h" #include "led.h" #include "can-halal.h" -#include "farbe.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/