diff options
Diffstat (limited to 'Colours.cpp')
-rw-r--r-- | Colours.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Colours.cpp b/Colours.cpp index b2ae38e..c121391 100644 --- a/Colours.cpp +++ b/Colours.cpp @@ -15,7 +15,41 @@ Colours::Colours(int rPin,int gPin,int bPin) { } void Colours::writeRGB(unsigned char r,unsigned char g,unsigned char b) { + analogWrite(_rPin, r); + analogWrite(_gPin, g); + analogWrite(_bPin, b); } void Colours::writeHSV(unsigned int h,unsigned char s,unsigned char v) { + h = h % 360; + if (s==0) { + writeRGB(v,v,v); + } else { + unsigned int f,p,q,t; + f = 256*(h%60)/60; + p = v*(256-s)/256; + q = v*(256-f*s/256)/256; + t = v*(256-s*(256-f)/256)/256; + switch( (h/60) % 6 ) { + case 0: + writeRGB(v,t,p); + break; + case 1: + writeRGB(q,v,p); + break; + case 2: + writeRGB(p,v,t); + break; + case 3: + writeRGB(p,q,v); + break; + case 4: + writeRGB(t,p,v); + break; + case 5: + writeRGB(v,p,q); + break; + } + } + } |