Eric Xu / Mbed 2 deprecated Arcade_RedX

Dependencies:   uLCD_4DGL_SE PinDetect SDFileSystem mbed wave_player

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RGBLED.h Source File

RGBLED.h

00001 /******************************************************
00002  * This header program declares all the functions and
00003  * variables used by RGB LED component.
00004  ******************************************************/
00005 
00006 
00007 // Class to control an RGB LED using three PWM pins
00008 class RGBLED {
00009     public:
00010         // RGBLED constructor
00011         RGBLED(PinName redPin, PinName greenPin, PinName bluePin) : red(redPin), green(greenPin), blue(bluePin) {
00012             red.period(0.0005);
00013             green.period(0.0005);
00014             blue.period(0.0005);
00015             red = 0.0;
00016             green = 0.0;
00017             blue = 0.0;
00018         }
00019 
00020         RGBLED operator=(int color) {
00021             write(color);
00022             return *this;
00023         }
00024 
00025 
00026     private:
00027         PwmOut red;
00028         PwmOut green;
00029         PwmOut blue;
00030 
00031         void write(int color) {
00032             red = (color >> 16) / 255.0 / 16.0;
00033             green = ((color >> 8) & 0xFF) / 255.0 / 16.0;
00034             blue = (color & 0xFF) / 255.0 / 16.0;
00035         }
00036 };