summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <elena.valhalla@gmail.com>2009-11-12 22:50:11 +0100
committerElena ``of Valhalla'' Grandi <elena.valhalla@gmail.com>2009-11-12 22:50:11 +0100
commit2692c4107384fc680f1df32a12b821d79a060e00 (patch)
treef68aee14bb7026e13ce93a48807b5b0f68fa3586
parentc66b57acbc0350c1277e501b779bb468506dc95e (diff)
WriteHSV function from the mood_lamp sketch
-rw-r--r--Colours.cpp34
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;
+ }
+ }
+
}