Update PwmPin.cpp
This commit is contained in:
parent
59e34fde05
commit
a8dff0a7de
|
|
@ -129,6 +129,8 @@ LedPin::LedPin(uint8_t pin, uint8_t level){
|
||||||
set(level);
|
set(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
|
||||||
void LedPin::set(uint8_t level){
|
void LedPin::set(uint8_t level){
|
||||||
if(!enabled)
|
if(!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
@ -140,6 +142,63 @@ void LedPin::set(uint8_t level){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
|
||||||
|
void LedPin::HSVtoRGB(float h, float s, float v, float *r, float *g, float *b ){
|
||||||
|
|
||||||
|
// The algorithm below was provided on the web at https://www.cs.rit.edu/~ncs/color/t_convert.html
|
||||||
|
// h = [0,360]
|
||||||
|
// s = [0,1]
|
||||||
|
// v = [0,1]
|
||||||
|
|
||||||
|
int i;
|
||||||
|
float f, p, q, t;
|
||||||
|
|
||||||
|
if( s == 0 ){
|
||||||
|
*r = *g = *b = v;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
h /= 60;
|
||||||
|
i = floor( h ) ;
|
||||||
|
f = h - i;
|
||||||
|
p = v * ( 1 - s );
|
||||||
|
q = v * ( 1 - s * f );
|
||||||
|
t = v * ( 1 - s * ( 1 - f ) );
|
||||||
|
switch( i % 6 ) {
|
||||||
|
case 0:
|
||||||
|
*r = v;
|
||||||
|
*g = t;
|
||||||
|
*b = p;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
*r = q;
|
||||||
|
*g = v;
|
||||||
|
*b = p;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
*r = p;
|
||||||
|
*g = v;
|
||||||
|
*b = t;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
*r = p;
|
||||||
|
*g = q;
|
||||||
|
*b = v;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
*r = t;
|
||||||
|
*g = p;
|
||||||
|
*b = v;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
*r = v;
|
||||||
|
*g = p;
|
||||||
|
*b = q;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
ServoPin::ServoPin(uint8_t channel, uint8_t pin, double initDegrees, uint16_t minMicros, uint16_t maxMicros, double minDegrees, double maxDegrees){
|
ServoPin::ServoPin(uint8_t channel, uint8_t pin, double initDegrees, uint16_t minMicros, uint16_t maxMicros, double minDegrees, double maxDegrees){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue