RGB_LED是一种有特色的器件,它将红绿蓝三种色彩集成在同一器件中,依赖这三基色可以组合出多种多样的色彩,那如何才能展示这种效果呢? 借助L432的多通道PWM输出功能可以轻松地实现这一功能,它只需一个RGB_LED、3个2K的限流电阻及少量导线即可。其显示效果如下图所示,程序只需将main()函数中的while(1){} 循环改为如下的程序就行了。 由于器件中的3个发光点并不在一点,所以色彩的混合效果不均匀,因此最好在该器件前附上一层纸来辅助混光。 色彩环变换效果图 - 色彩环变换效果程序:
- while (1)
- {
- for(n=0;n<3;n++) // 以三基色组合色彩
- {
- for(i=0;i<100;i++) // 调节色彩的亮度
- {
- if(n==0)
- {
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*(100-i)/100); // R
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*i/100); // G
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3);
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*0); // B
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1);
- }
- if(n==1)
- {
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*0); // R
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*(100-i)/100); // G
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3);
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*i/100); // B
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1);
- }
- if(n==2)
- {
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*i/100); // R
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*0); // G
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3);
- sConfig.Pulse = (uint32_t) (PERIOD_VALUE*(100-i)/100); // B
- HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
- HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1);
- }
- // 延时处理
- for(j=0;j<2000;j++)
- {
- for(k=0;k<2000;k++);
- }
- }
- }
复制代码
相关推荐:
NUCLEO-L432KC官方技术文档
STM32 L4系列超低功耗微控制器官方介绍
STM32L4单片机参考设计
STM32单片机官方开发工具一览
|
不贵,我是在网上买的,好像20个与快递费一样多。
引脚间距有点小
这个就是施工的工艺问题了,其实 ,我想用这种LED弄个阵列板,没有低成本的加工工艺啊
好像见过有成品板出售,你在网上扫扫。
哈,放假玩疯了!