Two simple classes for using the RGB led
Dependents: 4180-lab3-RTOS 4180-FinalProject
SimpleRGB.h@1:0008e30a2bda, 2016-10-10 (annotated)
- Committer:
- kswanson31
- Date:
- Mon Oct 10 01:56:26 2016 +0000
- Revision:
- 1:0008e30a2bda
- Parent:
- 0:7a3ee33c0a53
Moved operator overload to class definition
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kswanson31 | 0:7a3ee33c0a53 | 1 | #ifndef SIMPLERGB_H |
kswanson31 | 0:7a3ee33c0a53 | 2 | #define SIMPLERGB_H |
kswanson31 | 0:7a3ee33c0a53 | 3 | |
kswanson31 | 0:7a3ee33c0a53 | 4 | #include "mbed.h" |
kswanson31 | 0:7a3ee33c0a53 | 5 | |
kswanson31 | 0:7a3ee33c0a53 | 6 | class LightColor |
kswanson31 | 0:7a3ee33c0a53 | 7 | { |
kswanson31 | 0:7a3ee33c0a53 | 8 | public: |
kswanson31 | 0:7a3ee33c0a53 | 9 | LightColor(float r, float g, float b); |
kswanson31 | 0:7a3ee33c0a53 | 10 | float red; |
kswanson31 | 0:7a3ee33c0a53 | 11 | float green; |
kswanson31 | 0:7a3ee33c0a53 | 12 | float blue; |
kswanson31 | 0:7a3ee33c0a53 | 13 | }; |
kswanson31 | 0:7a3ee33c0a53 | 14 | |
kswanson31 | 0:7a3ee33c0a53 | 15 | class RGBLed |
kswanson31 | 0:7a3ee33c0a53 | 16 | { |
kswanson31 | 0:7a3ee33c0a53 | 17 | public: |
kswanson31 | 0:7a3ee33c0a53 | 18 | RGBLed(PinName rpin, PinName gpin, PinName bpin); |
kswanson31 | 0:7a3ee33c0a53 | 19 | void write(float red, float green, float blue); |
kswanson31 | 0:7a3ee33c0a53 | 20 | void write(LightColor color); |
kswanson31 | 1:0008e30a2bda | 21 | RGBLed operator = (LightColor color) { |
kswanson31 | 1:0008e30a2bda | 22 | write(color); |
kswanson31 | 1:0008e30a2bda | 23 | return *this; |
kswanson31 | 1:0008e30a2bda | 24 | }; |
kswanson31 | 0:7a3ee33c0a53 | 25 | |
kswanson31 | 0:7a3ee33c0a53 | 26 | private: |
kswanson31 | 0:7a3ee33c0a53 | 27 | PwmOut _rpin; |
kswanson31 | 0:7a3ee33c0a53 | 28 | PwmOut _gpin; |
kswanson31 | 0:7a3ee33c0a53 | 29 | PwmOut _bpin; |
kswanson31 | 0:7a3ee33c0a53 | 30 | }; |
kswanson31 | 0:7a3ee33c0a53 | 31 | |
kswanson31 | 0:7a3ee33c0a53 | 32 | #endif |
kswanson31 | 0:7a3ee33c0a53 | 33 | |
kswanson31 | 0:7a3ee33c0a53 | 34 | |
kswanson31 | 0:7a3ee33c0a53 | 35 |