RGB LED Class
Dependencies: mbed
Fork of RGBLED by
Revision 0:7c0b6a649748, committed 2014-06-09
- Comitter:
- rcflyair
- Date:
- Mon Jun 09 14:17:39 2014 +0000
- Commit message:
- First version non-library version without doxy
Changed in this revision
diff -r 000000000000 -r 7c0b6a649748 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jun 09 14:17:39 2014 +0000 @@ -0,0 +1,17 @@ +#include "mbed.h" +#include "rgbled.h" + +int main(void) +{ + rgbled rgb(PTB22, PTE26, PTB21); // create rgb object with pin definitions for FRDM-K64F board + rgb.active(false); // set led output to active low + rgb.set(none); // set led output of all off + while(1){ + rgb.set(red); + wait(1); + rgb.set(green); + wait(1); + rgb.set(blue); + wait(1); + } +} \ No newline at end of file
diff -r 000000000000 -r 7c0b6a649748 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Jun 09 14:17:39 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877 \ No newline at end of file
diff -r 000000000000 -r 7c0b6a649748 rgbled.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rgbled.cpp Mon Jun 09 14:17:39 2014 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" +#include "rgbled.h" + +rgbled::rgbled(PinName pin_red, PinName pin_green, PinName pin_blue) + : _pin_red(pin_red), _pin_green(pin_green), _pin_blue(pin_blue){ + _on = false; + _off = !_on; + _pin_red = _off; + _pin_green = _off; + _pin_blue = _off; +} + +void rgbled::active(bool a){ + _on = a; + _off = !_on; +} + +void rgbled::_none(void){ + _pin_red = _off; + _pin_green = _off; + _pin_blue = _off; +} + +void rgbled::_red(void){ + _pin_red = _on; + _pin_green = _off; + _pin_blue = _off; +} + +void rgbled::_green(void){ + _pin_red = _off; + _pin_green = _on; + _pin_blue = _off; +} + +void rgbled::_blue(void){ + _pin_red = _off; + _pin_green = _off; + _pin_blue = _on; +} + +void rgbled::set(color c){ + switch (c) { + case none : + _none(); + break; + case red : + _red(); + break; + case green : + _green(); + break; + case blue : + _blue(); + break; + } +}
diff -r 000000000000 -r 7c0b6a649748 rgbled.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rgbled.h Mon Jun 09 14:17:39 2014 +0000 @@ -0,0 +1,28 @@ +#ifndef __RGBLED_H__ +#define __RGBLED_H__ + +// includes +#include "mbed.h" + +// defines +enum color {none, red, green, blue}; + +// rgb led +class rgbled { +private: + DigitalOut _pin_red; + DigitalOut _pin_green; + DigitalOut _pin_blue; + bool _on; + bool _off; + void _none(void); + void _red(void); + void _green(void); + void _blue(void); +public: + rgbled(PinName pin_red, PinName pin_green, PinName pin_blue); + void active(bool a); + void set(color c); +}; + +#endif \ No newline at end of file