Library for led
RGB LED library
users/gimohd/code/LED/
[Not found]
lib/RGB.cpp@0:5368b27ca9d0, 2015-12-10 (annotated)
- Committer:
- gimohd
- Date:
- Thu Dec 10 15:06:29 2015 +0000
- Revision:
- 0:5368b27ca9d0
publis library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gimohd | 0:5368b27ca9d0 | 1 | |
gimohd | 0:5368b27ca9d0 | 2 | #include "RGB.h" |
gimohd | 0:5368b27ca9d0 | 3 | |
gimohd | 0:5368b27ca9d0 | 4 | RGB::RGB(PinName r_pin, PinName g_pin, PinName b_pin){ |
gimohd | 0:5368b27ca9d0 | 5 | this->r_out = new PwmOut(r_pin); |
gimohd | 0:5368b27ca9d0 | 6 | this->g_out = new PwmOut(g_pin); |
gimohd | 0:5368b27ca9d0 | 7 | this->b_out = new PwmOut(b_pin); |
gimohd | 0:5368b27ca9d0 | 8 | } |
gimohd | 0:5368b27ca9d0 | 9 | |
gimohd | 0:5368b27ca9d0 | 10 | float RGB::toFloat(int value){ |
gimohd | 0:5368b27ca9d0 | 11 | return (float) (255-value)/255; |
gimohd | 0:5368b27ca9d0 | 12 | }; |
gimohd | 0:5368b27ca9d0 | 13 | |
gimohd | 0:5368b27ca9d0 | 14 | void RGB::setColor(Color color){ |
gimohd | 0:5368b27ca9d0 | 15 | r_out->write(toFloat(color.getRed())); |
gimohd | 0:5368b27ca9d0 | 16 | g_out->write(toFloat(color.getGreen())); |
gimohd | 0:5368b27ca9d0 | 17 | b_out->write(toFloat(color.getBlue())); |
gimohd | 0:5368b27ca9d0 | 18 | } |
gimohd | 0:5368b27ca9d0 | 19 | |
gimohd | 0:5368b27ca9d0 | 20 | void RGB::setColor(int red,int green,int blue){ |
gimohd | 0:5368b27ca9d0 | 21 | r_out->write(toFloat(red)); |
gimohd | 0:5368b27ca9d0 | 22 | g_out->write(toFloat(green)); |
gimohd | 0:5368b27ca9d0 | 23 | b_out->write(toFloat(blue)); |
gimohd | 0:5368b27ca9d0 | 24 | } |
gimohd | 0:5368b27ca9d0 | 25 | |
gimohd | 0:5368b27ca9d0 | 26 | void RGB::setColor(int color){ |
gimohd | 0:5368b27ca9d0 | 27 | Color kleur = Color(color); |
gimohd | 0:5368b27ca9d0 | 28 | r_out->write(toFloat(kleur.getRed())); |
gimohd | 0:5368b27ca9d0 | 29 | g_out->write(toFloat(kleur.getGreen())); |
gimohd | 0:5368b27ca9d0 | 30 | b_out->write(toFloat(kleur.getBlue())); |
gimohd | 0:5368b27ca9d0 | 31 | |
gimohd | 0:5368b27ca9d0 | 32 | } |
gimohd | 0:5368b27ca9d0 | 33 | |
gimohd | 0:5368b27ca9d0 | 34 | void RGB::off(){ |
gimohd | 0:5368b27ca9d0 | 35 | r_out->write(0); |
gimohd | 0:5368b27ca9d0 | 36 | g_out->write(0); |
gimohd | 0:5368b27ca9d0 | 37 | b_out->write(0); |
gimohd | 0:5368b27ca9d0 | 38 | } |