Effects added :-)

This commit is contained in:
StefansE
2026-03-25 19:06:44 +01:00
parent 7aea97a648
commit 5a4d46bbba
6 changed files with 104 additions and 21 deletions

View File

@@ -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_ */

18
Core/Inc/ws2812_effect.h Normal file
View File

@@ -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_ */

View File

@@ -24,8 +24,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdlib.h>
#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++) {
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_RoudTheClock();
}
HAL_GPIO_TogglePin(LED_Green_GPIO_Port, LED_Green_Pin);
mytimer = HAL_GetTick();
while(mytimer + EFFECT_TIME > HAL_GetTick()){
ws_Effect_RandRound();
}
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 */

View File

@@ -5,9 +5,7 @@
* Author: ewars
*/
#include "stdint-gcc.h"
#include "ws2812.h"
#include <ws2812_drv.h>
#include "stm32f1xx_hal.h"
extern htim2;

60
Core/Src/ws2812_effect.c Normal file
View File

@@ -0,0 +1,60 @@
/*
* ws2812_effect.c
*
* Created on: Mar 25, 2026
* Author: ewars
*/
#include "ws2812_effect.h"
#include "ws2812_drv.h"
#include <stdlib.h>
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);
}

View File

@@ -83,5 +83,6 @@
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;/&gt;"/>
<stringAttribute key="process_factory_id" value="com.st.stm32cube.ide.mcu.debug.launch.HardwareDebugProcessFactory"/>
</launchConfiguration>