Library for led
RGB LED library
users/gimohd/code/LED/
[Not found]
lib/Color.cpp@4:dc9ce1a68604, 2015-12-10 (annotated)
- Committer:
- gimohd
- Date:
- Thu Dec 10 15:45:22 2015 +0000
- Revision:
- 4:dc9ce1a68604
- Parent:
- Color.cpp@3:18500db47a73
documentation not ready
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gimohd | 0:5368b27ca9d0 | 1 | |
gimohd | 0:5368b27ca9d0 | 2 | #include "Color.h" |
gimohd | 0:5368b27ca9d0 | 3 | |
gimohd | 0:5368b27ca9d0 | 4 | Color::Color(int red, int green, int blue){ |
gimohd | 0:5368b27ca9d0 | 5 | this->red = red; |
gimohd | 0:5368b27ca9d0 | 6 | this->green = green; |
gimohd | 0:5368b27ca9d0 | 7 | this->blue = blue; |
gimohd | 0:5368b27ca9d0 | 8 | } |
gimohd | 0:5368b27ca9d0 | 9 | |
gimohd | 0:5368b27ca9d0 | 10 | Color::Color(float red, float green, float blue){ |
gimohd | 0:5368b27ca9d0 | 11 | this->red = floatToColorValue(red); |
gimohd | 0:5368b27ca9d0 | 12 | this->green = floatToColorValue(green); |
gimohd | 0:5368b27ca9d0 | 13 | this->blue = floatToColorValue(blue); |
gimohd | 0:5368b27ca9d0 | 14 | } |
gimohd | 0:5368b27ca9d0 | 15 | |
gimohd | 0:5368b27ca9d0 | 16 | Color::Color(int color){ |
gimohd | 0:5368b27ca9d0 | 17 | this->red = (color >> 16) & 0x0000FF; |
gimohd | 0:5368b27ca9d0 | 18 | this->green = (color >> 8 ) & 0x0000FF; |
gimohd | 0:5368b27ca9d0 | 19 | this->blue = (color >> 0 ) & 0x0000FF; |
gimohd | 0:5368b27ca9d0 | 20 | } |
gimohd | 0:5368b27ca9d0 | 21 | |
gimohd | 0:5368b27ca9d0 | 22 | int Color::floatToColorValue(float value){ |
gimohd | 0:5368b27ca9d0 | 23 | return (int) (value * MAX_COLOR_VALUE); |
gimohd | 0:5368b27ca9d0 | 24 | }; |
gimohd | 0:5368b27ca9d0 | 25 | |
gimohd | 0:5368b27ca9d0 | 26 | int Color::getHex(){ |
gimohd | 0:5368b27ca9d0 | 27 | return (red << 16) + (green<<8) + (blue <<0); |
gimohd | 0:5368b27ca9d0 | 28 | } |
gimohd | 0:5368b27ca9d0 | 29 | |
gimohd | 0:5368b27ca9d0 | 30 | int Color::getRed(){ |
gimohd | 0:5368b27ca9d0 | 31 | return red; |
gimohd | 0:5368b27ca9d0 | 32 | } |
gimohd | 0:5368b27ca9d0 | 33 | |
gimohd | 0:5368b27ca9d0 | 34 | int Color::getGreen(){ |
gimohd | 0:5368b27ca9d0 | 35 | return green; |
gimohd | 0:5368b27ca9d0 | 36 | } |
gimohd | 0:5368b27ca9d0 | 37 | |
gimohd | 0:5368b27ca9d0 | 38 | int Color::getBlue(){ |
gimohd | 0:5368b27ca9d0 | 39 | return blue; |
gimohd | 0:5368b27ca9d0 | 40 | } |
gimohd | 0:5368b27ca9d0 | 41 |