Two simple classes for using the RGB led
Dependents: 4180-lab3-RTOS 4180-FinalProject
SimpleRGB.cpp@0:7a3ee33c0a53, 2016-10-10 (annotated)
- Committer:
- kswanson31
- Date:
- Mon Oct 10 00:32:31 2016 +0000
- Revision:
- 0:7a3ee33c0a53
- Child:
- 1:0008e30a2bda
Two simple classes for using RGB led
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kswanson31 | 0:7a3ee33c0a53 | 1 | #include "SimpleRGB.h" |
kswanson31 | 0:7a3ee33c0a53 | 2 | |
kswanson31 | 0:7a3ee33c0a53 | 3 | |
kswanson31 | 0:7a3ee33c0a53 | 4 | // construct a LightColor object |
kswanson31 | 0:7a3ee33c0a53 | 5 | LightColor::LightColor(float r, float g, float b) |
kswanson31 | 0:7a3ee33c0a53 | 6 | : red(r), green(g), blue(b) |
kswanson31 | 0:7a3ee33c0a53 | 7 | { |
kswanson31 | 0:7a3ee33c0a53 | 8 | } |
kswanson31 | 0:7a3ee33c0a53 | 9 | |
kswanson31 | 0:7a3ee33c0a53 | 10 | // construct an RGBLed object |
kswanson31 | 0:7a3ee33c0a53 | 11 | RGBLed::RGBLed(PinName rpin, PinName gpin, PinName bpin) |
kswanson31 | 0:7a3ee33c0a53 | 12 | : _rpin(rpin), _gpin(gpin), _bpin(bpin) |
kswanson31 | 0:7a3ee33c0a53 | 13 | { |
kswanson31 | 0:7a3ee33c0a53 | 14 | //50Hz PWM clock default a bit too low, go to 2000Hz (less flicker) |
kswanson31 | 0:7a3ee33c0a53 | 15 | _rpin.period(0.0005); |
kswanson31 | 0:7a3ee33c0a53 | 16 | } |
kswanson31 | 0:7a3ee33c0a53 | 17 | |
kswanson31 | 0:7a3ee33c0a53 | 18 | // write directly to an RGBLed object |
kswanson31 | 0:7a3ee33c0a53 | 19 | void RGBLed::write(float red, float green, float blue) { |
kswanson31 | 0:7a3ee33c0a53 | 20 | _rpin = red; |
kswanson31 | 0:7a3ee33c0a53 | 21 | _gpin = green; |
kswanson31 | 0:7a3ee33c0a53 | 22 | _bpin = blue; |
kswanson31 | 0:7a3ee33c0a53 | 23 | } |
kswanson31 | 0:7a3ee33c0a53 | 24 | |
kswanson31 | 0:7a3ee33c0a53 | 25 | // use a LightColor object to change the RGBLed |
kswanson31 | 0:7a3ee33c0a53 | 26 | void RGBLed::write(LightColor color) { |
kswanson31 | 0:7a3ee33c0a53 | 27 | _rpin = color.red; |
kswanson31 | 0:7a3ee33c0a53 | 28 | _gpin = color.green; |
kswanson31 | 0:7a3ee33c0a53 | 29 | _bpin = color.blue; |
kswanson31 | 0:7a3ee33c0a53 | 30 | } |
kswanson31 | 0:7a3ee33c0a53 | 31 | |
kswanson31 | 0:7a3ee33c0a53 | 32 | // alow assingment of LightColor object to the RGBLed object |
kswanson31 | 0:7a3ee33c0a53 | 33 | RGBLed operator = (LightColor color) { |
kswanson31 | 0:7a3ee33c0a53 | 34 | write(color); |
kswanson31 | 0:7a3ee33c0a53 | 35 | return *this; |
kswanson31 | 0:7a3ee33c0a53 | 36 | } |