sqefqsdf
Dependencies: C12832 EthernetInterface LM75B mbed-rtos mbed
Fork of app-board-LM75B by
RGB.cpp@6:77a4c45f6416, 2017-03-23 (annotated)
- Committer:
- gimohd
- Date:
- Thu Mar 23 12:51:27 2017 +0000
- Revision:
- 6:77a4c45f6416
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gimohd | 6:77a4c45f6416 | 1 | |
gimohd | 6:77a4c45f6416 | 2 | #include "RGB.h" |
gimohd | 6:77a4c45f6416 | 3 | |
gimohd | 6:77a4c45f6416 | 4 | RGB::RGB(PinName r_pin, PinName g_pin, PinName b_pin) |
gimohd | 6:77a4c45f6416 | 5 | { |
gimohd | 6:77a4c45f6416 | 6 | this->r_out = new PwmOut(r_pin); |
gimohd | 6:77a4c45f6416 | 7 | this->g_out = new PwmOut(g_pin); |
gimohd | 6:77a4c45f6416 | 8 | this->b_out = new PwmOut(b_pin); |
gimohd | 6:77a4c45f6416 | 9 | } |
gimohd | 6:77a4c45f6416 | 10 | |
gimohd | 6:77a4c45f6416 | 11 | RGB::~RGB() |
gimohd | 6:77a4c45f6416 | 12 | { |
gimohd | 6:77a4c45f6416 | 13 | delete r_out; |
gimohd | 6:77a4c45f6416 | 14 | delete g_out; |
gimohd | 6:77a4c45f6416 | 15 | delete b_out; |
gimohd | 6:77a4c45f6416 | 16 | delete color; |
gimohd | 6:77a4c45f6416 | 17 | } |
gimohd | 6:77a4c45f6416 | 18 | |
gimohd | 6:77a4c45f6416 | 19 | float RGB::toFloat(int value) |
gimohd | 6:77a4c45f6416 | 20 | { |
gimohd | 6:77a4c45f6416 | 21 | return (float) (255-value)/255; |
gimohd | 6:77a4c45f6416 | 22 | }; |
gimohd | 6:77a4c45f6416 | 23 | |
gimohd | 6:77a4c45f6416 | 24 | void RGB::setColor(Color color) |
gimohd | 6:77a4c45f6416 | 25 | { |
gimohd | 6:77a4c45f6416 | 26 | r_out->write(toFloat(color.getRed())); |
gimohd | 6:77a4c45f6416 | 27 | g_out->write(toFloat(color.getGreen())); |
gimohd | 6:77a4c45f6416 | 28 | b_out->write(toFloat(color.getBlue())); |
gimohd | 6:77a4c45f6416 | 29 | this->color = &color; |
gimohd | 6:77a4c45f6416 | 30 | } |
gimohd | 6:77a4c45f6416 | 31 | |
gimohd | 6:77a4c45f6416 | 32 | void RGB::setColor(int red,int green,int blue) |
gimohd | 6:77a4c45f6416 | 33 | { |
gimohd | 6:77a4c45f6416 | 34 | r_out->write(toFloat(red)); |
gimohd | 6:77a4c45f6416 | 35 | g_out->write(toFloat(green)); |
gimohd | 6:77a4c45f6416 | 36 | b_out->write(toFloat(blue)); |
gimohd | 6:77a4c45f6416 | 37 | this->color = new Color(red,green,blue); |
gimohd | 6:77a4c45f6416 | 38 | } |
gimohd | 6:77a4c45f6416 | 39 | |
gimohd | 6:77a4c45f6416 | 40 | void RGB::setColor(int color) |
gimohd | 6:77a4c45f6416 | 41 | { |
gimohd | 6:77a4c45f6416 | 42 | Color * kleur = new Color(color); |
gimohd | 6:77a4c45f6416 | 43 | r_out->write(toFloat(kleur->getRed())); |
gimohd | 6:77a4c45f6416 | 44 | g_out->write(toFloat(kleur->getGreen())); |
gimohd | 6:77a4c45f6416 | 45 | b_out->write(toFloat(kleur->getBlue())); |
gimohd | 6:77a4c45f6416 | 46 | this->color = kleur; |
gimohd | 6:77a4c45f6416 | 47 | } |
gimohd | 6:77a4c45f6416 | 48 | void RGB::setRgbColor(int WheelPos) |
gimohd | 6:77a4c45f6416 | 49 | { |
gimohd | 6:77a4c45f6416 | 50 | if(WheelPos < 85) { |
gimohd | 6:77a4c45f6416 | 51 | RGB::setColor(255 - WheelPos * 3, 0, WheelPos * 3); |
gimohd | 6:77a4c45f6416 | 52 | } else if(WheelPos < 170) { |
gimohd | 6:77a4c45f6416 | 53 | WheelPos -= 85; |
gimohd | 6:77a4c45f6416 | 54 | RGB::setColor(0, WheelPos * 3, 255 - WheelPos * 3); |
gimohd | 6:77a4c45f6416 | 55 | } else { |
gimohd | 6:77a4c45f6416 | 56 | WheelPos -= 170; |
gimohd | 6:77a4c45f6416 | 57 | RGB::setColor(WheelPos * 3, 255 - WheelPos * 3, 0); |
gimohd | 6:77a4c45f6416 | 58 | } |
gimohd | 6:77a4c45f6416 | 59 | } |
gimohd | 6:77a4c45f6416 | 60 | |
gimohd | 6:77a4c45f6416 | 61 | |
gimohd | 6:77a4c45f6416 | 62 | |
gimohd | 6:77a4c45f6416 | 63 | void RGB::off() |
gimohd | 6:77a4c45f6416 | 64 | { |
gimohd | 6:77a4c45f6416 | 65 | r_out->write(1); |
gimohd | 6:77a4c45f6416 | 66 | g_out->write(1); |
gimohd | 6:77a4c45f6416 | 67 | b_out->write(1); |
gimohd | 6:77a4c45f6416 | 68 | } |