Browse Source

Working demo without segments feature

master
Mateusz Salamon 7 years ago
parent
commit
54859cae64
  1. 6
      Inc/ws2812b_fx.h
  2. 5
      README.md
  3. 43
      Src/main.c
  4. 21
      Src/ws2812b_fx.c

6
Inc/ws2812b_fx.h

@ -25,7 +25,7 @@
#define DEFAULT_BRIGHTNESS 50 #define DEFAULT_BRIGHTNESS 50
#define BRIGHTNESS_MAX 255 #define BRIGHTNESS_MAX 255
#define MODE_COUNT 62 #define MODE_COUNT 58
#define DEFAULT_MODE 0 #define DEFAULT_MODE 0
#define FADE_RATE 2 #define FADE_RATE 2
@ -121,8 +121,8 @@ 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_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_SetColorHSV(uint8_t id, uint16_t h, uint8_t s, uint8_t v);
void WS2812BFX_SetColor(uint8_t id, uint32_t c); void WS2812BFX_SetColor(uint8_t id, uint32_t c);
void WS2812BFX_SetColorAll(uint32_t c); void WS2812BFX_SetAll(uint32_t c);
void WS2812BFX_SetColorAllRGB(uint8_t r, uint8_t g, uint8_t b); void WS2812BFX_SetAllRGB(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_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); void WS2812BFX_HSVtoRGB(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g, uint8_t *b);

5
README.md

@ -4,5 +4,10 @@ www.msalamon.pl
Diodes are driving by SPI interface with DMA. Diodes are driving by SPI interface with DMA.
Library description:
https://msalamon.pl/adresowalne-diody-ws2812b-na-stm32-cz-1/
https://msalamon.pl/adresowalne-diody-ws2812b-na-stm32-cz-2/
The FX library is based od WS2812FX Arduino librarby by kitesurfer1404 - https://github.com/kitesurfer1404/WS2812FX The FX library is based od WS2812FX Arduino librarby by kitesurfer1404 - https://github.com/kitesurfer1404/WS2812FX

43
Src/main.c

@ -57,13 +57,20 @@
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "ws2812b.h" #include "ws2812b.h"
#include "ws2812b_fx.h" #include "ws2812b_fx.h"
#include "usbd_cdc_if.h"
#define MODE_DELAY 15000
/* USER CODE END Includes */ /* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */ /* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
uint8_t USBDataTX[40]; // Array for transmission USB messages
uint8_t USBDataLength; // USB message length
volatile uint16_t ModeTimer;
uint8_t Mode;
/* USER CODE END PV */ /* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
@ -112,13 +119,17 @@ int main(void)
MX_USB_DEVICE_Init(); MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
WS2812B_Init(&hspi1); WS2812B_Init(&hspi1);
WS2812BFX_SetSpeed(5000); WS2812BFX_SetSpeed(150);
WS2812BFX_SetColorRGB(0, 0,255,0); WS2812BFX_SetColorRGB(0, 0,0,0);
WS2812BFX_SetColorRGB(1, 32,0,0); WS2812BFX_SetColorRGB(1, 64,0,0);
WS2812BFX_SetColorRGB(2, 0,64,0); WS2812BFX_SetColorRGB(2, 0,0,64);
WS2812BFX_SetMode(FX_MODE_WHITE_TO_COLOR);
Mode = 0;
WS2812BFX_SetMode(Mode);
WS2812BFX_Start(); WS2812BFX_Start();
WS2812BFX_SetColorRGB(0, 0, 64,0);
ModeTimer = MODE_DELAY;
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
@ -129,6 +140,27 @@ int main(void)
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
WS2812BFX_Callback(); WS2812BFX_Callback();
if(!ModeTimer)
{
for(uint8_t i = 0; i < WS2812B_LEDS; i++)
WS2812B_SetDiodeColor(i, 0);
WS2812B_Refresh();
USBDataLength = sprintf((char*)USBDataTX, "Mode number: %d\n\r", Mode);
CDC_Transmit_FS(USBDataTX, USBDataLength);
if(Mode == 1 || Mode == 2)
WS2812BFX_SetSpeed(3000);
else
WS2812BFX_SetSpeed(200);
WS2812BFX_SetMode(Mode);
if(Mode < MODE_COUNT - 1) Mode++;
else Mode = 0;
ModeTimer = MODE_DELAY;
}
} }
/* USER CODE END 3 */ /* USER CODE END 3 */
@ -197,6 +229,7 @@ void SystemClock_Config(void)
void HAL_SYSTICK_Callback(void) void HAL_SYSTICK_Callback(void)
{ {
WS2812BFX_SysTickCallback(); WS2812BFX_SysTickCallback();
if(ModeTimer) ModeTimer--;
} }
/* USER CODE END 4 */ /* USER CODE END 4 */

21
Src/ws2812b_fx.c

@ -228,24 +228,17 @@ void WS2812BFX_SetColor(uint8_t id, uint32_t c)
mColor_w[id].blue = (c&0x000000FF); mColor_w[id].blue = (c&0x000000FF);
} }
void WS2812BFX_SetColorAll(uint32_t c) void WS2812BFX_SetAll(uint32_t c)
{ {
mColor[0] = c;
mColor_w[0].red = ((c>>16)&0x000000FF);
mColor_w[0].green = ((c>>8)&0x000000FF);
mColor_w[0].blue = (c&0x000000FF);
for(uint16_t i = 0; i < WS2812B_LEDS; i++) for(uint16_t i = 0; i < WS2812B_LEDS; i++)
{ {
WS2812B_SetDiodeRGB(i, mColor_w[0].red, mColor_w[0].green, mColor_w[0].blue); WS2812B_SetDiodeRGB(i, ((c>>16)&0xFF), ((c>>8)&0xFF), (c&0xFF));
} }
} }
void WS2812BFX_SetColorAllRGB(uint8_t r, uint8_t g, uint8_t b) void WS2812BFX_SetAllRGB(uint8_t r, uint8_t g, uint8_t b)
{ {
mColor[0] = ((r<<16)|(g<<8)|b);
mColor_w[0].red = r;
mColor_w[0].green = g;
mColor_w[0].blue = b;
for(uint16_t i = 0; i < WS2812B_LEDS; i++) for(uint16_t i = 0; i < WS2812B_LEDS; i++)
{ {
WS2812B_SetDiodeRGB(i, r, g, b); WS2812B_SetDiodeRGB(i, r, g, b);
@ -629,7 +622,7 @@ void mode_black_to_color(void)
void blink(uint32_t color1, uint32_t color2, uint8_t strobe) void blink(uint32_t color1, uint32_t color2, uint8_t strobe)
{ {
uint32_t color = ((mCounterModeCall & 1) == 0) ? color1 : color2; uint32_t color = ((mCounterModeCall & 1) == 0) ? color1 : color2;
WS2812BFX_SetColorAll(color); WS2812BFX_SetAll(color);
if((mCounterModeCall & 1) == 0) if((mCounterModeCall & 1) == 0)
iModeDelay = strobe ? 20 : mSpeed / 2; iModeDelay = strobe ? 20 : mSpeed / 2;
else else
@ -679,7 +672,7 @@ void mode_breath(void)
uint8_t g = mModeColor_w[0].green * lum / 256; uint8_t g = mModeColor_w[0].green * lum / 256;
uint8_t b = mModeColor_w[0].blue * lum / 256; uint8_t b = mModeColor_w[0].blue * lum / 256;
WS2812BFX_SetColorAllRGB(r, g, b); WS2812BFX_SetAllRGB(r, g, b);
mCounterModeStep += 2; mCounterModeStep += 2;
if(mCounterModeStep > (512-15)) mCounterModeStep = 15; if(mCounterModeStep > (512-15)) mCounterModeStep = 15;
iModeDelay = delay; iModeDelay = delay;
@ -776,7 +769,7 @@ void mode_color_sweep_random(void)
void mode_random_color(void) void mode_random_color(void)
{ {
mAuxParam = get_random_wheel_index(mAuxParam); // aux_param will store our random color wheel index mAuxParam = get_random_wheel_index(mAuxParam); // aux_param will store our random color wheel index
WS2812BFX_SetColorAll(color_wheel(mAuxParam)); WS2812BFX_SetAll(color_wheel(mAuxParam));
iModeDelay = mSpeed; iModeDelay = mSpeed;
} }

Loading…
Cancel
Save