极品馒头泬19p,国产精品亚洲一区二区三区,狠狠色噜噜狠狠狠7777奇米,国产精品视频一区二区三区无码,国产欧美日韩久久久久

【E812】WS2812B漸變色流水算法+PWM DMA驅(qū)動(dòng)STM32源程序

2021-09-06 08:54:19      索煒達(dá)電子      3090     

項(xiàng)目編號(hào):E812

文件大?。?99K

源碼說(shuō)明:帶中文注釋

開(kāi)發(fā)環(huán)境:C編譯器

簡(jiǎn)要概述:

最近在學(xué)習(xí)STM32,到定時(shí)器與DMA章節(jié),正巧手頭有先前買的WS2812B模塊,查找相關(guān)資料,于是成功點(diǎn)亮了,
又按照自己想法和思路寫了一個(gè)漸變色算法,和漸變色流水功能,

可自定義燈的數(shù)量和漸變色的深度

漸變色原理:
假如紅藍(lán)兩色變換
紅(亮度):10   8   6   4   2   0
藍(lán)(亮度):0     2   4   6   8   10

這樣就形成兩種顏色的過(guò)度
加大其分辨率,兩顏色之間顏色差越小,生成顏色數(shù)據(jù)越多

在流水過(guò)程中,顏色取到數(shù)組末尾時(shí),要將數(shù)組首端的數(shù)據(jù)加在末尾,使其顏色無(wú)差別連接

控制代碼:

生成三種顏色數(shù)據(jù)數(shù)組

  1. /**

  2. * color_length 每種顏色漸變最大長(zhǎng)度,總顏色長(zhǎng)度:color_length * 3

  3. * return 顏色數(shù)據(jù)總長(zhǎng)度

  4. */

  5. uint32_t set_Color_Loop(uint8_t color_length)

  6. {

  7.     RGB = (uint32_t*)malloc(color_length*3*sizeof(uint32_t));//分配數(shù)組大小,(所有漸變色顏色長(zhǎng)度)

  8.     color_length -= 1;

  9.     for(uint8_t i=0;i<=color_length;i++)

  10.     {

  11.         RGB[i] = (((0xff/color_length)*i)<<8)|((0xff/color_length)*(color_length-i));                                       //藍(lán)到綠

  12.         RGB[color_length + 1 +i] = (((0xff/color_length)*i)<<16)|((0xff/color_length)*(color_length-i))<<8; //綠到紅

  13.         RGB[((color_length+1)*2) +i] = ((0xff/color_length)*i)|((0xff/color_length)*(color_length-i))<<16;   //紅到藍(lán)

  14.     }

  15.     return color_length*3;

  16. }



  17. 無(wú)間斷位移獲取8位顏色數(shù)據(jù)

  18. /**

  19. * colorwidth 每次獲取多少位

  20. */


  21. void out_RGB(uint16_t data_Max_Length,uint16_t colorwidth)

  22. {

  23.     static uint32_t rgb_position = 0;

  24.     for(uint32_t i = 0;i < colorwidth; i++){

  25.         uint16_t c = (rgb_position + i) % data_Max_Length;//末尾顏色數(shù)據(jù)結(jié)束時(shí)將首位的收據(jù)填充到數(shù)組

  26.         send_Data(RGB[c]);

  27.     }

  28.     rgb_position ++;

  29.     rgb_position %= data_Max_Length;

  30. }

【E812】WS2812B漸變色流水算法+PWM DMA驅(qū)動(dòng)STM32源程序

【E812】WS2812B漸變色流水算法+PWM DMA驅(qū)動(dòng)STM32源程序

目錄│文件列表:

 └ WS2812B

    │ keilkill.bat

    ├ Doc

    │  └ readme.txt

    ├ Libraries

    │  ├ CMSIS

    │  │  │ core_cm3.c

    │  │  │ core_cm3.h

    │  │  │ stm32f10x.h

    │  │  │ system_stm32f10x.c

    │  │  │ system_stm32f10x.h

    │  │  └ startup

    │  │     │ startup_stm32f10x_cl.s

    │  │     │ startup_stm32f10x_hd.s

    │  │     │ startup_stm32f10x_hd_vl.s

    │  │     │ startup_stm32f10x_ld.s

    │  │     │ startup_stm32f10x_ld_vl.s

    │  │     │ startup_stm32f10x_md.s

    │  │     │ startup_stm32f10x_md_vl.s

    │  │     └ startup_stm32f10x_xl.s

    │  └ STM32F10x_StdPeriph_Driver

    │     ├ inc

    │     │  │ misc.h

    │     │  │ stm32f10x_adc.h

    │     │  │ stm32f10x_bkp.h

    │     │  │ stm32f10x_can.h

    │     │  │ stm32f10x_cec.h

    │     │  │ stm32f10x_crc.h

    │     │  │ stm32f10x_dac.h

    │     │  │ stm32f10x_dbgmcu.h

    │     │  │ stm32f10x_dma.h

    │     │  │ stm32f10x_exti.h

    │     │  │ stm32f10x_flash.h

    │     │  │ stm32f10x_fsmc.h

    │     │  │ stm32f10x_gpio.h

    │     │  │ stm32f10x_i2c.h

    │     │  │ stm32f10x_iwdg.h

    │     │  │ stm32f10x_pwr.h

    │     │  │ stm32f10x_rcc.h

    │     │  │ stm32f10x_rtc.h

    │     │  │ stm32f10x_sdio.h

    │     │  │ stm32f10x_spi.h

    │     │  │ stm32f10x_tim.h

    │     │  │ stm32f10x_usart.h

    │     │  └ stm32f10x_wwdg.h

    │     └ src

    │        │ misc.c

    │        │ stm32f10x_adc.c

    │        │ stm32f10x_bkp.c

    │        │ stm32f10x_can.c

    │        │ stm32f10x_cec.c

    │        │ stm32f10x_crc.c

    │        │ stm32f10x_dac.c

    │        │ stm32f10x_dbgmcu.c

    │        │ stm32f10x_dma.c

    │        │ stm32f10x_exti.c

    │        │ stm32f10x_flash.c

    │        │ stm32f10x_fsmc.c

    │        │ stm32f10x_gpio.c

    │        │ stm32f10x_i2c.c

    │        │ stm32f10x_iwdg.c

    │        │ stm32f10x_pwr.c

    │        │ stm32f10x_rcc.c

    │        │ stm32f10x_rtc.c

    │        │ stm32f10x_sdio.c

    │        │ stm32f10x_spi.c

    │        │ stm32f10x_tim.c

    │        │ stm32f10x_usart.c

    │        └ stm32f10x_wwdg.c

    ├ Project

    │  │ BH-F103.uvguix.KaiXuan

    │  │ BH-F103.uvoptx

    │  │ BH-F103.uvprojx

    │  │ EventRecorderStub.scvd

    │  ├ DebugConfig

    │  │  └ Target_1_STM32F103ZE_1.0.0.dbgconf

    │  └ Objects

    │     │ BH-F103.hex

    │     └ BH-F103.sct

    └ User

       │ main.c

       │ main.c.orig

       │ stm32f10x_conf.h

       │ stm32f10x_conf.h.orig

       │ stm32f10x_it.c

       │ stm32f10x_it.c.orig

       │ stm32f10x_it.h

       │ stm32f10x_it.h.orig

       ├ delay

       │  │ delay.c

       │  └ delay.h

       ├ sys

       │  │ sys.c

       │  └ sys.h

       ├ usart

       │  │ usart.c

       │  └ usart.h

       └ W2812B

          │ WS2812B.c

          └ WS2812B.h

TAGWS2812B
  • 25 次
  • 1 分