小安派Knob的例程中有个可以通过旋钮调节LED色温和亮度的例程,在这个基础上简单添加上可以切换其他颜色的功能
这里以简单地红绿蓝为例,在枚举中添加RGB
- typedef enum {
- LIGHT_CCK_WARM,
- LIGHT_CCK_COOL,
- //加入RGB枚举
- LIGHT_CCK_R,
- LIGHT_CCK_G,
- LIGHT_CCK_B,
- LIGHT_CCK_MAX,
- } LIGHT_CCK_TYPE;
复制代码 在处理旋钮点击的地方修改切换方式
- else if (LV_EVENT_CLICKED == code) {
- // light_set_conf.light_cck = \
- // (LIGHT_CCK_WARM == light_set_conf.light_cck) ? (LIGHT_CCK_COOL) : (LIGHT_CCK_WARM);
- //修改灯光切换
- if(light_set_conf.light_cck < LIGHT_CCK_MAX - 1 )
- light_set_conf.light_cck += 1;
- else
- light_set_conf.light_cck = 0;
- set_light_warm_cool();
- }
复制代码 在处理PWM输出的地方加入计算RGB值的方法
- // if (LIGHT_CCK_COOL == light_xor.light_cck) {
- // pwm_RGB_start(light_xor.light_pwm, light_xor.light_pwm, light_xor.light_pwm);
- // // RGB_color = (0xFF * light_xor.light_pwm / 100) << 16 | (0xFF * light_xor.light_pwm / 100) << 8 | (0xFF * light_xor.light_pwm / 100) << 0;
- // } else {
- // pwm_RGB_start(light_xor.light_pwm, light_xor.light_pwm, 0);
- // // RGB_color = (0xFF * light_xor.light_pwm / 100) << 16 | (0xFF * light_xor.light_pwm / 100) << 8 | (0x33 * light_xor.light_pwm / 100) << 0;
- // }
- //修改PWM输出
- switch (light_xor.light_cck)
- {
- case LIGHT_CCK_COOL:
- r = 100;
- g = 100;
- b = 100;
- break;
- case LIGHT_CCK_WARM:
- r = 100;
- g = 100;
- b = 0;
- break;
- case LIGHT_CCK_R:
- r = 100;
- g = 0;
- b = 0;
- break;
- case LIGHT_CCK_G:
- r = 0;
- g = 100;
- b = 0;
- break;
- case LIGHT_CCK_B:
- r = 0;
- g = 0;
- b = 100;
- break;
-
- default:
- break;
- }
- pwm_RGB_start(light_xor.light_pwm*r/100, light_xor.light_pwm*g/100, light_xor.light_pwm*b/100);
复制代码 最终实现效果,点按切换颜色
旋转切换亮度
|