Browse Source

FX effects for whole strip.

Based in WS2812BFX Arduino library by kitesurfer1404.
Every effect concerns whole strip -  no segments.
I added also HSV color mode and two FX modes related to it.
master
Mateusz Salamon 7 years ago
parent
commit
1d3ded9080
  1. 5
      Inc/ws2812b.h
  2. 196
      Inc/ws2812b_fx.h
  3. 5
      README.md
  4. 95
      Src/main.c
  5. 23
      Src/ws2812b.c
  6. 1673
      Src/ws2812b_fx.c

5
Inc/ws2812b.h

@ -20,9 +20,12 @@ typedef struct ws2812b_color {
} ws2812b_color; } ws2812b_color;
void WS2812B_Init(SPI_HandleTypeDef * spi_handler); void WS2812B_Init(SPI_HandleTypeDef * spi_handler);
void WS2812B_SetDiodeColor(int16_t diode_id, ws2812b_color color); void WS2812B_SetDiodeColor(int16_t diode_id, uint32_t color);
void WS2812B_SetDiodeColorStruct(int16_t diode_id, ws2812b_color color);
void WS2812B_SetDiodeRGB(int16_t diode_id, uint8_t R, uint8_t G, uint8_t B); void WS2812B_SetDiodeRGB(int16_t diode_id, uint8_t R, uint8_t G, uint8_t B);
void WS2812B_SetDiodeHSV(int16_t diode_id, uint16_t Hue, uint8_t Saturation, uint8_t Brightness); void WS2812B_SetDiodeHSV(int16_t diode_id, uint16_t Hue, uint8_t Saturation, uint8_t Brightness);
uint32_t WS2812B_GetColor(int16_t diode_id);
uint8_t* WS2812B_GetPixels(void);
void WS2812B_Refresh(); void WS2812B_Refresh();
// color correction // color correction

196
Inc/ws2812b_fx.h

@ -0,0 +1,196 @@
/*
* ws2812b_fx.h
*
* Library based on Harm Aldick's Arduino library
* https://github.com/kitesurfer1404/WS2812FX
*
* The MIT License.
* Created on: 20.10.2018
* Author: Mateusz Salamon
* www.msalamon.pl
* mateusz@msalamon.pl
*/
#ifndef WS2812B_FX_H_
#define WS2812B_FX_H_
#define DEFAULT_COLOR 0x00FF000000
#define NUM_COLORS 3
#define SPEED_MIN 10
#define DEFAULT_SPEED 150
#define SPEED_MAX 65535
#define BRIGHTNESS_MIN 0
#define DEFAULT_BRIGHTNESS 50
#define BRIGHTNESS_MAX 255
#define MODE_COUNT 62
#define DEFAULT_MODE 0
#define FADE_RATE 2
// some common colors
#define RED (uint32_t)0xFF0000
#define GREEN (uint32_t)0x00FF00
#define BLUE (uint32_t)0x0000FF
#define WHITE (uint32_t)0xFFFFFF
#define BLACK (uint32_t)0x000000
#define YELLOW (uint32_t)0xFFFF00
#define CYAN (uint32_t)0x00FFFF
#define MAGENTA (uint32_t)0xFF00FF
#define PURPLE (uint32_t)0x400080
#define ORANGE (uint32_t)0xFF3000
#define PINK (uint32_t)0xFF1493
typedef enum {
FX_MODE_STATIC,
FX_MODE_WHITE_TO_COLOR,
FX_MODE_BLACK_TO_COLOR,
FX_MODE_BLINK,
FX_MODE_BLINK_RAINBOW,
FX_MODE_STROBE,
FX_MODE_STROBE_RAINBOW,
FX_MODE_BREATH,
FX_MODE_COLOR_WIPE,
FX_MODE_COLOR_WIPE_INV,
FX_MODE_COLOR_WIPE_REV,
FX_MODE_COLOR_WIPE_REV_INV,
FX_MODE_COLOR_WIPE_RANDOM,
FX_MODE_COLOR_SWEEP_RANDOM,
FX_MODE_RANDOM_COLOR,
FX_MODE_SINGLE_DYNAMIC,
FX_MODE_MULTI_DYNAMIC,
FX_MODE_RAINBOW,
FX_MODE_RAINBOW_CYCLE,
FX_MODE_FADE,
FX_MODE_SCAN,
FX_MODE_DUAL_SCAN,
FX_MODE_THEATER_CHASE,
FX_MODE_THEATER_CHASE_RAINBOW,
FX_MODE_RUNNING_LIGHTS,
FX_MODE_TWINKLE,
FX_MODE_TWINKLE_RANDOM,
FX_MODE_TWINKLE_FADE,
FX_MODE_TWINKLE_FADE_RANDOM,
FX_MODE_SPARKLE,
FX_MODE_FLASH_SPARKLE,
FX_MODE_HYPER_SPARKLE,
FX_MODE_MULTI_STROBE,
FX_MODE_CHASE_WHITE,
FX_MODE_CHASE_COLOR,
FX_MODE_CHASE_RANDOM,
FX_MODE_CHASE_RAINBOW,
FX_MODE_CHASE_FLASH,
FX_MODE_CHASE_FLASH_RANDOM,
FX_MODE_CHASE_RAINBOW_WHITE,
FX_MODE_CHASE_BLACKOUT,
FX_MODE_CHASE_BLACKOUT_RAINBOW,
FX_MODE_RUNNING_COLOR,
FX_MODE_RUNNING_RED_BLUE,
FX_MODE_RUNNING_RANDOM,
FX_MODE_LARSON_SCANNER,
FX_MODE_COMET,
FX_MODE_FIREWORKS,
FX_MODE_FIREWORKS_RANDOM,
FX_MODE_MERRY_CHRISTMAS,
FX_MODE_FIRE_FLICKER,
FX_MODE_FIRE_FLICKER_SOFT,
FX_MODE_FIRE_FLICKER_INTENSE,
FX_MODE_CIRCUS_COMBUSTUS,
FX_MODE_HALLOWEEN,
FX_MODE_BICOLOR_CHASE,
FX_MODE_TRICOLOR_CHASE,
FX_MODE_ICU,
} fx_mode;
void WS2812BFX_SysTickCallback(void);
void WS2812BFX_Callback(void);
void WS2812BFX_Start(void);
void WS2812BFX_Stop(void);
void WS2812BFX_SetMode(fx_mode mode);
void WS2812BFX_NextMode(void);
void WS2812BFX_PrevMode(void);
void WS2812BFX_SetSpeed(uint16_t Speed);
void WS2812BFX_IncreaseSpeed(uint16_t Speed);
void WS2812BFX_DecreaseSpeed(uint16_t Speed);
void WS2812BFX_SetColorStruct(uint8_t id, ws2812b_color c);
void WS2812BFX_SetColorRGB(uint8_t id, uint8_t r, uint8_t g, uint8_t b);
void WS2812BFX_SetColorHSV(uint8_t id, uint16_t h, uint8_t s, uint8_t v);
void WS2812BFX_SetColor(uint8_t id, uint32_t c);
void WS2812BFX_SetColorAll(uint32_t c);
void WS2812BFX_SetColorAllRGB(uint8_t r, uint8_t g, uint8_t b);
void WS2812BFX_RGBtoHSV(uint8_t r, uint8_t g, uint8_t b, uint16_t *h, uint8_t *s, uint8_t *v);
void WS2812BFX_HSVtoRGB(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);
/*
*
* MODES
*
* */
void
strip_off(void),
mode_static(void),
mode_white_to_color(void),
mode_black_to_color(void),
mode_blink(void),
mode_blink_rainbow(void),
mode_strobe(void),
mode_strobe_rainbow(void),
mode_breath(void),
mode_color_wipe(void),
mode_color_wipe_inv(void),
mode_color_wipe_rev(void),
mode_color_wipe_rev_inv(void),
mode_color_wipe_random(void),
mode_color_sweep_random(void),
mode_random_color(void),
mode_single_dynamic(void),
mode_multi_dynamic(void),
mode_rainbow(void),
mode_rainbow_cycle(void),
mode_fade(void),
mode_scan(void),
mode_dual_scan(void),
mode_theater_chase(void),
mode_theater_chase_rainbow(void),
mode_running_lights(void),
mode_twinkle(void),
mode_twinkle_random(void),
mode_twinkle_fade(void),
mode_twinkle_fade_random(void),
mode_sparkle(void),
mode_flash_sparkle(void),
mode_hyper_sparkle(void),
mode_multi_strobe(void),
mode_chase_white(void),
mode_chase_color(void),
mode_chase_random(void),
mode_chase_rainbow(void),
mode_chase_flash(void),
mode_chase_flash_random(void),
mode_chase_rainbow_white(void),
mode_chase_blackout(void),
mode_chase_blackout_rainbow(void),
mode_running_color(void),
mode_running_red_blue(void),
mode_running_random(void),
mode_larson_scanner(void),
mode_comet(void),
mode_fireworks(void),
mode_fireworks_random(void),
mode_merry_christmas(void),
mode_fire_flicker(void),
mode_fire_flicker_soft(void),
mode_fire_flicker_intense(void),
mode_circus_combustus(void),
mode_halloween(void),
mode_bicolor_chase(void),
mode_tricolor_chase(void),
mode_icu(void)
;
#endif /* WS2812B_FX_H_ */

5
README.md

@ -1,5 +1,8 @@
WS2812B diodes using STM32F103C8T6 MCU. WS2812B diodes using STM32F103C8T6 MCU.
www.msalamon.pl
Diodes are driving by SPI interface with DMA. Diodes are driving by SPI interface with DMA.
Color could be changed by RGB color model. The FX library is based od WS2812FX Arduino librarby by kitesurfer1404 - https://github.com/kitesurfer1404/WS2812FX

95
Src/main.c

@ -45,16 +45,14 @@
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "ws2812b.h" #include "ws2812b.h"
#include "ws2812b_fx.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */ /* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
ws2812b_color color;
uint8_t R[] = {255,0,0,255,0,128,0,0,128,0,64,0,0,64,0,32,0,0,32,0,16,0,0,16,0,8,0,0,8,0};
uint8_t G[] = {0,255,0,255,255,0,128,0,255,255,0,64,0,64,64,0,32,0,32,32,0,16,0,16,16,0,8,0,8,8};
uint8_t B[] = {0,0,255,0,255,0,0,128,0,255,0,0,64,0,64,0,0,32,0,32,0,0,16,0,18,0,0,8,0,8};
/* USER CODE END PV */ /* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
@ -101,18 +99,14 @@ int main(void)
MX_DMA_Init(); MX_DMA_Init();
MX_SPI1_Init(); MX_SPI1_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, 1);
WS2812B_Init(&hspi1); WS2812B_Init(&hspi1);
for(uint8_t i = 0; i <= WS2812B_LEDS; i++) WS2812BFX_SetSpeed(5000);
{ WS2812BFX_SetColorRGB(0, 0,255,0);
color.red = 0; WS2812BFX_SetColorRGB(1, 32,0,0);
color.green = 0; WS2812BFX_SetColorRGB(2, 0,64,0);
color.blue = 0; WS2812BFX_SetMode(FX_MODE_WHITE_TO_COLOR);
WS2812B_SetDiodeColor(i,color); WS2812BFX_Start();
}
WS2812B_Refresh();
uint16_t j;
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
@ -122,72 +116,8 @@ int main(void)
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
WS2812BFX_Callback();
// HSV Value manipulation demo }
for(int loop = 0; loop < 10; loop++)
{
for(int v =0; v<256; v++)
{
for(uint8_t i = 0; i <= WS2812B_LEDS; i++)
{
j = (360/35) * i;
WS2812B_SetDiodeHSV(i, j, 255, v);
}
HAL_Delay(1);
WS2812B_Refresh();
}
for(int v =255; v>-1; v--)
{
for(uint8_t i = 0; i <= WS2812B_LEDS; i++)
{
j = 360/35 * i;
WS2812B_SetDiodeHSV(i, j, 255, v);
}
HAL_Delay(1);
WS2812B_Refresh();
}
}
// RGB manipulation demo
for(int v =0; v<30; v++)
{
for(uint8_t i = 0; i <= WS2812B_LEDS; i++)
{
WS2812B_SetDiodeRGB(i, R[v], G[v], B[v]);
}
HAL_Delay(500);
WS2812B_Refresh();
}
// HSV Saturation manipulation demo
for(int loop = 0; loop < 10; loop++)
{
for(int v =0; v<256; v++)
{
for(uint8_t i = 0; i <= WS2812B_LEDS; i++)
{
j = (360/35) * i;
WS2812B_SetDiodeHSV(i, j, v, 255);
}
HAL_Delay(1);
WS2812B_Refresh();
}
for(int v =255; v>-1; v--)
{
for(uint8_t i = 0; i <= WS2812B_LEDS; i++)
{
j = 360/35 * i;
WS2812B_SetDiodeHSV(i, j, v, 255);
}
HAL_Delay(1);
WS2812B_Refresh();
}
}
HAL_Delay(10);
}
/* USER CODE END 3 */ /* USER CODE END 3 */
@ -244,7 +174,10 @@ void SystemClock_Config(void)
} }
/* USER CODE BEGIN 4 */ /* USER CODE BEGIN 4 */
void HAL_SYSTICK_Callback(void)
{
WS2812BFX_SysTickCallback();
}
/* USER CODE END 4 */ /* USER CODE END 4 */
/** /**

23
Src/ws2812b.c

@ -31,7 +31,15 @@ void WS2812B_Init(SPI_HandleTypeDef * spi_handler)
hspi_ws2812b = spi_handler; hspi_ws2812b = spi_handler;
} }
void WS2812B_SetDiodeColor(int16_t diode_id, ws2812b_color color) void WS2812B_SetDiodeColor(int16_t diode_id, uint32_t color)
{
if(diode_id >= WS2812B_LEDS || diode_id < 0) return;
ws2812b_array[diode_id].red = ((color>>16)&0x000000FF);
ws2812b_array[diode_id].green = ((color>>8)&0x000000FF);
ws2812b_array[diode_id].blue = (color&0x000000FF);
}
void WS2812B_SetDiodeColorStruct(int16_t diode_id, ws2812b_color color)
{ {
if(diode_id >= WS2812B_LEDS || diode_id < 0) return; if(diode_id >= WS2812B_LEDS || diode_id < 0) return;
ws2812b_array[diode_id] = color; ws2812b_array[diode_id] = color;
@ -45,6 +53,19 @@ void WS2812B_SetDiodeRGB(int16_t diode_id, uint8_t R, uint8_t G, uint8_t B)
ws2812b_array[diode_id].blue = B; ws2812b_array[diode_id].blue = B;
} }
uint32_t WS2812B_GetColor(int16_t diode_id)
{
uint32_t color = 0;
color |= ((ws2812b_array[diode_id].red&0xFF)<<16);
color |= ((ws2812b_array[diode_id].green&0xFF)<<8);
color |= (ws2812b_array[diode_id].blue&0xFF);
return color;
}
uint8_t* WS2812B_GetPixels(void)
{
return (uint8_t*)ws2812b_array;
}
// //
// Set diode with HSV model // Set diode with HSV model
// //

1673
Src/ws2812b_fx.c

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save