From 5a4d46bbbac148343e07e018bb25ca87b1e4873c Mon Sep 17 00:00:00 2001 From: StefansE Date: Wed, 25 Mar 2026 19:06:44 +0100 Subject: [PATCH] Effects added :-) --- .../Inc/ws2812.h => Core/Inc/ws2812_drv.h | 8 ++- Core/Inc/ws2812_effect.h | 18 ++++++ Core/Src/main.c | 34 ++++++----- .../Src/ws2812.c => Core/Src/ws2812_drv.c | 4 +- Core/Src/ws2812_effect.c | 60 +++++++++++++++++++ LedRing Run.launch | 1 + 6 files changed, 104 insertions(+), 21 deletions(-) rename Drivers/STM32F1xx_HAL_Driver/Inc/ws2812.h => Core/Inc/ws2812_drv.h (72%) create mode 100644 Core/Inc/ws2812_effect.h rename Drivers/STM32F1xx_HAL_Driver/Src/ws2812.c => Core/Src/ws2812_drv.c (96%) create mode 100644 Core/Src/ws2812_effect.c diff --git a/Drivers/STM32F1xx_HAL_Driver/Inc/ws2812.h b/Core/Inc/ws2812_drv.h similarity index 72% rename from Drivers/STM32F1xx_HAL_Driver/Inc/ws2812.h rename to Core/Inc/ws2812_drv.h index 61205ad..8fb5226 100644 --- a/Drivers/STM32F1xx_HAL_Driver/Inc/ws2812.h +++ b/Core/Inc/ws2812_drv.h @@ -5,8 +5,10 @@ * Author: ewars */ -#ifndef STM32F1XX_HAL_DRIVER_INC_WS2812_H_ -#define STM32F1XX_HAL_DRIVER_INC_WS2812_H_ +#ifndef INC_WS2812_DRV_H_ +#define INC_WS2812_DRV_H_ + +#include "stdint-gcc.h" #define LED_N 24 @@ -23,4 +25,4 @@ void ws2812_wait(void); void ws2812_reset(void); -#endif /* STM32F1XX_HAL_DRIVER_INC_WS2812_H_ */ +#endif /* INC_WS2812_DRV_H_ */ diff --git a/Core/Inc/ws2812_effect.h b/Core/Inc/ws2812_effect.h new file mode 100644 index 0000000..0ee82c5 --- /dev/null +++ b/Core/Inc/ws2812_effect.h @@ -0,0 +1,18 @@ +/* + * ws2812_effect.h + * + * Created on: Mar 25, 2026 + * Author: ewars + */ + +#ifndef INC_WS2812_EFFECT_H_ +#define INC_WS2812_EFFECT_H_ + + +void ws_Effect_RoudTheClock(void); +void ws_Effect_RandRound(void); +void ws_Effect_RandRand(void); + + + +#endif /* INC_WS2812_EFFECT_H_ */ diff --git a/Core/Src/main.c b/Core/Src/main.c index 2ad6793..2b769af 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -24,8 +24,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include -#include "ws2812.h" +#include "ws2812_effect.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -98,6 +97,8 @@ int main(void) ws2812_Init(); + uint32_t mytimer = 0; + /* USER CODE END 2 */ @@ -109,24 +110,27 @@ int main(void) /* USER CODE BEGIN 3 */ - uint8_t r = rand(); - uint8_t g = rand(); - uint8_t b = rand(); +#define EFFECT_TIME 5000 - for (uint8_t led = 0; led < 24; led++) { + mytimer = HAL_GetTick(); + while(mytimer + EFFECT_TIME > HAL_GetTick()){ + ws_Effect_RoudTheClock(); + } - uint8_t r = rand(); - uint8_t g = rand(); - uint8_t b = rand(); - ws2812_reset(); - - ws2812_set_colour(led, r, g, b); - ws2812_update(); - HAL_Delay(20); + mytimer = HAL_GetTick(); + while(mytimer + EFFECT_TIME > HAL_GetTick()){ + ws_Effect_RandRound(); } - HAL_GPIO_TogglePin(LED_Green_GPIO_Port, LED_Green_Pin); + + mytimer = HAL_GetTick(); + while(mytimer + EFFECT_TIME > HAL_GetTick()){ + ws_Effect_RandRand(); + } + + + //HAL_GPIO_TogglePin(LED_Green_GPIO_Port, LED_Green_Pin); } /* USER CODE END 3 */ diff --git a/Drivers/STM32F1xx_HAL_Driver/Src/ws2812.c b/Core/Src/ws2812_drv.c similarity index 96% rename from Drivers/STM32F1xx_HAL_Driver/Src/ws2812.c rename to Core/Src/ws2812_drv.c index c3e4fb4..6f0253a 100644 --- a/Drivers/STM32F1xx_HAL_Driver/Src/ws2812.c +++ b/Core/Src/ws2812_drv.c @@ -5,9 +5,7 @@ * Author: ewars */ -#include "stdint-gcc.h" - -#include "ws2812.h" +#include #include "stm32f1xx_hal.h" extern htim2; diff --git a/Core/Src/ws2812_effect.c b/Core/Src/ws2812_effect.c new file mode 100644 index 0000000..7c3e451 --- /dev/null +++ b/Core/Src/ws2812_effect.c @@ -0,0 +1,60 @@ +/* + * ws2812_effect.c + * + * Created on: Mar 25, 2026 + * Author: ewars + */ + + +#include "ws2812_effect.h" +#include "ws2812_drv.h" +#include + +void ws_Effect_RoudTheClock(void){ + + uint8_t r = rand(); + uint8_t g = rand(); + uint8_t b = rand(); + + for (uint8_t led = 0; led < 24; led++) { + + ws2812_reset(); + + ws2812_set_colour(led, r, g, b); + ws2812_update(); + HAL_Delay(20); + } + +} + + +void ws_Effect_RandRound(void){ + + uint8_t r = rand(); + uint8_t g = rand(); + uint8_t b = rand(); + + for (uint8_t led = 0; led < 24; led++) { + + + ws2812_set_colour(led, r, g, b); + ws2812_update(); + HAL_Delay(20); + } +} + + +void ws_Effect_RandRand(void){ + + #define RAND_MAX 255 + uint8_t r = rand(); + uint8_t g = rand(); + uint8_t b = rand(); + + #define RAND_MAX 24 + uint8_t led = rand(); + + ws2812_set_colour(led, r, g, b); + ws2812_update(); + HAL_Delay(1); +} diff --git a/LedRing Run.launch b/LedRing Run.launch index 24abcbb..f0d1a5a 100644 --- a/LedRing Run.launch +++ b/LedRing Run.launch @@ -83,5 +83,6 @@ +