/* * Colours - library for managing the colours on RGB LEDs */ #include "Arduino.h" #include "Colours.h" Colours::Colours(int rPin,int gPin,int bPin) { _rPin = rPin; _gPin = gPin; _bPin = bPin; pinMode(_rPin,OUTPUT); pinMode(_gPin,OUTPUT); pinMode(_bPin,OUTPUT); } 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; } } }