秉火429笔记之五控制RGB彩灯
生活随笔
收集整理的這篇文章主要介紹了
秉火429笔记之五控制RGB彩灯
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1. RGB彩燈混色
RGB彩燈實(shí)際上由三盞分別為紅、綠、藍(lán)的LED燈組成的,通過控制RGB顏色強(qiáng)度的組合,可以混合出各種彩色。
/* 基本混色*/// LED1(R)/ LED2(G)/ LED3(B)//紅 #define LED_RED \LED1_ON;\LED2_OFF;\LED3_OFF//綠 #define LED_GREEN \LED1_OFF;\LED2_ON;\LED3_OFF//藍(lán) #define LED_BLUE \LED1_OFF;\LED2_OFF;\LED3_ON//黃(紅+綠) #define LED_YELLOW \LED1_ON;\LED2_ON;\LED3_OFF //紫(紅+藍(lán)) #define LED_PURPLE \LED1_ON;\LED2_OFF;\LED3_ON//青(綠+藍(lán)) #define LED_CYAN \LED1_OFF;\LED2_ON;\LED3_ON//白(紅+綠+藍(lán)) #define LED_WHITE \LED1_ON;\LED2_ON;\LED3_ON//黑(全部關(guān)閉) #define LED_RGBOFF \LED1_OFF;\LED2_OFF;\LED3_OFF2. 控制流程
- 初始化系統(tǒng)時(shí)鐘
- 初始化相應(yīng)GPIO時(shí)鐘
- 配置GPIO
- 根據(jù)需要亮燈
3. 斷言
stm32f4xx_conf.h文件中關(guān)于斷言的定義
/* Uncomment the line below to expanse the "assert_param" macro in the Standard Peripheral Library drivers code */ /* #define USE_FULL_ASSERT 1 *//* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT/*** @brief The assert_param macro is used for function's parameters check.* @param expr: If expr is false, it calls assert_failed function* which reports the name of the source file and the source* line number of the call that failed. * If expr is true, it returns no value.* @retval None*/#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */void assert_failed(uint8_t* file, uint32_t line); #else#define assert_param(expr) ((void)0) #endif /* USE_FULL_ASSERT */庫(kù)文件只對(duì)“assert_failed”寫了函數(shù)聲明,沒有寫函數(shù)定義,實(shí)際用時(shí)需要用戶來定義,我們一般會(huì)用printf函數(shù)來輸出這些信息。(注:前提需要支持printf)
4. Doxygen注釋
“Doxygen”的注釋規(guī)范,如果在工程文件中按照這種規(guī)范去注釋,可以使用Doxygen軟件自動(dòng)根據(jù)注釋生成幫助文檔。
總結(jié)
以上是生活随笔為你收集整理的秉火429笔记之五控制RGB彩灯的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS逆向之巨量算数signature与d
- 下一篇: 蓝桥杯 历届试题 小朋友排队 C++