Grove LCD Library

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Grove_LCD_RGB_Backlight.h Source File

Grove_LCD_RGB_Backlight.h

00001 #include "mbed.h"
00002 
00003 // I2C addresses for LCD and RGB
00004 #define LCD_ADDRESS     (0x7c)
00005 #define RGB_ADDRESS     (0xc4)
00006 
00007 #define RED_REG         0x04        
00008 #define GREEN_REG       0x03        
00009 #define BLUE_REG        0x02        
00010 
00011 // commands
00012 #define LCD_CLEARDISPLAY 0x01
00013 #define LCD_DISPLAYCONTROL 0x08
00014 #define LCD_FUNCTIONSET 0x20
00015 
00016 // flags for display on/off control
00017 #define LCD_DISPLAYON 0x04
00018 #define LCD_DISPLAYOFF 0x00
00019 
00020 // flag for entry mode
00021 #define LCD_ENTRYLEFT 0x02
00022 
00023 // flags for function set
00024 #define LCD_8BITMODE 0x10
00025 #define LCD_2LINE 0x08
00026 #define LCD_5x10DOTS 0x04
00027 
00028 /** Grove_LCD_RGB_Backlight Class.
00029 *   Used for connecting a Grove LCD RGB Backlit display
00030 *   to an mbed microcontroller via an I2C interface.
00031 */    
00032 class Grove_LCD_RGB_Backlight
00033 {
00034 public:
00035     
00036     /** Contructor. Creates an instance of the Grove_LCD_RGB_Backlight class.
00037     *   @param sda SDA pin on the mbed microcontroller which will be used to communicate with the display.
00038     *   @param scl SCL pin on the mbed microcontroller which will be used to communicate with the display.
00039     */
00040     Grove_LCD_RGB_Backlight(PinName sda, PinName scl); 
00041     
00042 
00043     
00044     /** Set RGB color of backlight
00045     *   @param r Value for the red component of the RGB backlight (Between 0 and 255).
00046     *   @param g Value for the green component of the RGB backlight (Between 0 and 255).
00047     *   @param b Value for the blue component of the RGB backlight (Between 0 and 255).
00048     */
00049     void setRGB(char r, char g, char b);     
00050     
00051     
00052     /** Removes all of the text from the display.
00053     */
00054     void clear();
00055     
00056     // This function in conjunction with hex2dec will output BCD values
00057     // on the LCD screen
00058     void write(char data1);
00059     
00060     // This function will output characters both ASCII and ALTERNATE
00061     void writech(char data2);
00062     
00063     /**Prints text to the LCD display.
00064     * @param *str Pointer to an array of characters which will be printed to the LCD screen.
00065     */
00066     void print(char *str);
00067     
00068     /**Move cursor to specified location on the LCD screen.
00069     * @param col Value for which column on the display the next text being printed will start at.
00070     * @param row Value for which row on the display the next text being printed will be printed on.
00071     */
00072     void locate(char col, char row);
00073 
00074     
00075 private:
00076     
00077     //Initialize device
00078     void init();   
00079     
00080     //Turn on display
00081     void displayOn();
00082     
00083     //Send command to display
00084     void sendCommand(char value);
00085     
00086     //Set register value
00087     void setReg(char addr, char val);
00088     
00089     //MBED I2C object used to transfer data to LCD
00090     I2C i2c;              
00091     
00092 };