Shiftbrite class
Revision 0:8322a6c71e18, committed 2013-02-13
- Comitter:
- zchen311
- Date:
- Wed Feb 13 05:52:25 2013 +0000
- Commit message:
Changed in this revision
Shiftbrite.cpp | Show annotated file Show diff for this revision Revisions of this file |
Shiftbrite.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 8322a6c71e18 Shiftbrite.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Shiftbrite.cpp Wed Feb 13 05:52:25 2013 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" +#include "Shiftbrite.h" + + + + +Shiftbrite::Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do,PinName pin_di, PinName pin_clk): _pin_e(pin_e), _pin_l(pin_l), _spi(pin_do, pin_di, pin_clk) +{ + SPI _spi(pin_do, pin_di, pin_clk); + _pin_l=0; + _pin_e=0; + _spi.format(16,0); + _spi.frequency(500000); +} + + +void Shiftbrite::RGB(int red, int green, int blue){ + + unsigned int low_color=0; + unsigned int high_color=0; + high_color=(blue<<4)|((red&0x3C0)>>6); + low_color=(((red&0x3F)<<10)|(green)); + _spi.write(high_color); + _spi.write(low_color); + _pin_l=1; + _pin_l=0; + + } + + \ No newline at end of file
diff -r 000000000000 -r 8322a6c71e18 Shiftbrite.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Shiftbrite.h Wed Feb 13 05:52:25 2013 +0000 @@ -0,0 +1,16 @@ +#include "mbed.h" + + +class Shiftbrite{ +public: + Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do,PinName pin_di, PinName pin_clk); + void RGB(int red, int green, int blue); + + + private: + DigitalOut _pin_e; + DigitalOut _pin_l; + SPI _spi; + + + }; \ No newline at end of file