Ernest Williams / Mbed 2 deprecated Bluetooth

Dependencies:   mbed Motor Servo

Fork of SerialPassthrough_LPC1768 by jim hamblen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Shiftbrite.h Source File

Shiftbrite.h

00001 #include "mbed.h"
00002 
00003 //Setup a new class for a Shiftbrite RGB LED module
00004 class Shiftbrite
00005 {
00006 public:
00007     Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk);
00008     void write(int red, int green, int blue);
00009 
00010 private:
00011 //class sets up the pins
00012     DigitalOut _pin_e;
00013     DigitalOut _pin_l;
00014     SPI _spi;
00015 };
00016 
00017 Shiftbrite::Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk)
00018     : _pin_e(pin_e), _pin_l(pin_l), _spi(pin_do, pin_di, pin_clk)
00019 {
00020 _pin_e=0;
00021 _pin_l=0;
00022 }
00023 
00024 void Shiftbrite::write(int red, int green, int blue)
00025 {
00026 long colors=0;
00027 long c=00;
00028 
00029 red=red*4;
00030 green=green*4;
00031 blue=blue*4;
00032 
00033 if(red>1023){
00034     red=1023;
00035     }
00036 if(green>1023){
00037     green=1023;
00038     }
00039 if(blue>1023){
00040     blue=1023;
00041     }
00042 colors=(colors<<2)|(c&3);
00043 colors=(colors<<10)|(blue&1023);
00044 colors=(colors<<10)|(red&1023);
00045 colors=(colors<<10)|(green&1023);
00046 
00047 long s1=0xFF000000;
00048 long s2=0xFF0000;
00049 long s3=0xFF00;
00050 long s4=0xFF;
00051 
00052 _spi.write((s1&colors)>>24);
00053 _spi.write((s2&colors)>>16);
00054 _spi.write((s3&colors)>>8);
00055 _spi.write(s4&colors);
00056 _pin_l=1;
00057 _pin_l=0;
00058 }