forked from PAWPAW/lib_rgb
添加了RGB平滑下降的代码示例
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "samples_to_levels.h"
|
||||
#include "rgb_effect.h"
|
||||
#include "timer.h"
|
||||
void test_cycleHSV_with_vol_level_example()
|
||||
void cycleHSV_vol_level_example()
|
||||
{
|
||||
uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定
|
||||
uint32_t current_hue = 0; // 从红色开始的当前色相值
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
|
||||
|
||||
extern "C"{
|
||||
void test_cycleHSV_with_vol_level_example();
|
||||
void cycleHSV_vol_level_example();
|
||||
}
|
||||
|
||||
int main() // 定义主函数
|
||||
@@ -22,7 +22,7 @@ int main() // 定义主函数
|
||||
{
|
||||
on tile[1]:
|
||||
{
|
||||
test_cycleHSV_with_vol_level_example();
|
||||
cycleHSV_vol_level_example();
|
||||
}
|
||||
}
|
||||
return 0; // 返回0,表示程序正常结束
|
||||
24
examples/app_cycleHSV_vol_level_smooth_example/Makefile
Normal file
24
examples/app_cycleHSV_vol_level_smooth_example/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
|
||||
|
||||
TARGET = XCORE-AI-EXPLORER
|
||||
|
||||
# 编译选项
|
||||
# 构建应用程序时传递给 xcc 的参数
|
||||
# O2: xcc编译器优化等级2
|
||||
# report: 打开编译报告
|
||||
# g: 生成调试信息
|
||||
# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
|
||||
BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
|
||||
|
||||
USED_MODULES = lib_rgb
|
||||
|
||||
XCC_FLAGS = $(BUILD_FLAGS)
|
||||
|
||||
XMOS_MODULE_PATH = ../../..
|
||||
XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
|
||||
|
||||
#=============================================================================
|
||||
# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
|
||||
|
||||
XMOS_MAKE_PATH ?= ../..
|
||||
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> // 包含基本的输入输出函数
|
||||
#include "samples_to_levels.h"
|
||||
#include "rgb_effect.h"
|
||||
#include "timer.h"
|
||||
#define DELAY_DECREASE 20 // 降低亮度时的额外延迟
|
||||
|
||||
// 该函数用于平滑过渡HSV颜色和音量级别
|
||||
void cycleHSV_vol_level_smooth_example()
|
||||
{
|
||||
uint32_t buf[NUM_RGBS]; // 存储RGB值的缓冲区
|
||||
uint32_t current_hue = 0; // 当前色调
|
||||
uint32_t current_color[NUM_RGB_GROUPS] = {0x000000, 0x000000}; // 当前颜色数组
|
||||
size_t random_levels[NUM_RGB_GROUPS]; // 随机音量级别数组
|
||||
size_t previous_levels[NUM_RGB_GROUPS] = {0}; // 存储先前的音量级别
|
||||
|
||||
srand(1); // 设置随机数种子
|
||||
|
||||
while (1) // 无限循环
|
||||
{
|
||||
for (size_t i = 0; i < NUM_RGB_GROUPS; i++) // 遍历RGB组
|
||||
{
|
||||
// 获取新的随机音量级别
|
||||
random_levels[i] = get_volume_level(rand() % 101 - 100);
|
||||
// 如果新的级别低于之前的级别,逐渐降低
|
||||
while (previous_levels[i] > random_levels[i])
|
||||
{
|
||||
previous_levels[i]--; // 降低当前级别
|
||||
// 用当前颜色和级别填充渐变
|
||||
fill_gradient_with_groups(buf, current_color, previous_levels);
|
||||
delay_milliseconds(DELAY_TIME_RGB); // 延迟
|
||||
// 更新每一步的RGB颜色
|
||||
for (size_t j = 0; j < NUM_RGB_GROUPS; j++)
|
||||
{
|
||||
current_color[j] = cycleHSV(¤t_hue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 用随机颜色和级别填充渐变
|
||||
fill_gradient_with_groups(buf, current_color, random_levels);
|
||||
delay_milliseconds(DELAY_TIME_RGB); // 延迟
|
||||
|
||||
// 更新当前颜色
|
||||
for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
|
||||
{
|
||||
current_color[i] = cycleHSV(¤t_hue);
|
||||
}
|
||||
|
||||
// 更新先前的音量级别
|
||||
for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
|
||||
{
|
||||
previous_levels[i] = random_levels[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
24
examples/app_cycleHSV_vol_level_smooth_example/src/main.xc
Normal file
24
examples/app_cycleHSV_vol_level_smooth_example/src/main.xc
Normal file
@@ -0,0 +1,24 @@
|
||||
/** @brief 平滑过渡HSV颜色和音量级别
|
||||
* @author Vergil Wong
|
||||
* @date 2023-11-25
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
#include <platform.h> // 包含对封装的定义,引用以使用 on tile[] 语法
|
||||
|
||||
extern "C"{
|
||||
void cycleHSV_vol_level_smooth_example();
|
||||
}
|
||||
|
||||
int main() // 定义主函数
|
||||
{
|
||||
par
|
||||
{
|
||||
on tile[1]:
|
||||
{
|
||||
cycleHSV_vol_level_smooth_example();
|
||||
}
|
||||
}
|
||||
return 0; // 返回0,表示程序正常结束
|
||||
}
|
||||
Reference in New Issue
Block a user