HSV转RGB C51 code

#define RGB_LIMIT 255
void LED_HSV_Control(uint16_t h, uint16_t s, uint16_t v)
{
// R,G,B from 0-255, H from 0-360, S,V from 0-1000
int i,difs;
unsigned char r,g,b;
long RGB_min, RGB_max,RGB_Adj;

RGB_max = v*RGB_LIMIT/1000;    //(v*RGB_LIMIT)/1000  //此处有1000倍
RGB_min = RGB_max *(1000 - s)/1000;

i = h / 60;
difs = h % 60; // factorial part of h

				   // RGB adjustment amount by hue 
RGB_Adj = (RGB_max - RGB_min)*difs / 60;

switch (i) {
case 0:
	r = RGB_max;    //(v*255)/1000
	g = RGB_min + RGB_Adj;
	b = RGB_min;
	break;
case 1:
	r = (RGB_max - RGB_Adj);
	g = RGB_max;
	b = RGB_min;
	break;
case 2:
	r = RGB_min;
	g = RGB_max;
	b = RGB_min + RGB_Adj;
	break;
case 3:
	r = RGB_min;
	g = RGB_max - RGB_Adj;
	b = RGB_max/1000;
	break;
case 4:
	r = RGB_min + RGB_Adj;
	g = RGB_min;
	b = RGB_max;
	break;
default:		// case 5:
	r = RGB_max;
	g = RGB_min;
	b = RGB_max - RGB_Adj;
	break;
}
DEBUG_INT("\r\n H %u",h);
DEBUG_INT("\r\n S %u",s);
DEBUG_INT("\r\n V %u",v);
DEBUG_INT("\r\nLED_R %bu",r);
DEBUG_INT("\r\nLED_G %bu",g);
DEBUG_INT("\r\nLED_B %bu\r\n",b);
LED_RGB_Control(r,g,b);

}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值