Code used to connect the Grove RGB LCD display to an mbed microcontroller.

Dependents:   Grove_LCD_RGB_Backlight_HelloWorld Test_BERTIN LASS_LoRa_mbed Affichage_MesureEnvironnement ... more

Committer:
cmatz3
Date:
Tue Mar 15 18:05:14 2016 +0000
Revision:
2:5ce38ef7a7db
Parent:
1:40a3b6506c9f
Fixed spelling error in docs;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cmatz3 0:253885b1f364 1 #include "mbed.h"
cmatz3 0:253885b1f364 2
cmatz3 0:253885b1f364 3 // I2C addresses for LCD and RGB
cmatz3 0:253885b1f364 4 #define LCD_ADDRESS (0x7c)
cmatz3 0:253885b1f364 5 #define RGB_ADDRESS (0xc4)
cmatz3 0:253885b1f364 6
cmatz3 0:253885b1f364 7 #define RED_REG 0x04
cmatz3 0:253885b1f364 8 #define GREEN_REG 0x03
cmatz3 0:253885b1f364 9 #define BLUE_REG 0x02
cmatz3 0:253885b1f364 10
cmatz3 0:253885b1f364 11 // commands
cmatz3 0:253885b1f364 12 #define LCD_CLEARDISPLAY 0x01
cmatz3 0:253885b1f364 13 #define LCD_DISPLAYCONTROL 0x08
cmatz3 0:253885b1f364 14 #define LCD_FUNCTIONSET 0x20
cmatz3 0:253885b1f364 15
cmatz3 0:253885b1f364 16 // flags for display on/off control
cmatz3 0:253885b1f364 17 #define LCD_DISPLAYON 0x04
cmatz3 0:253885b1f364 18 #define LCD_DISPLAYOFF 0x00
cmatz3 0:253885b1f364 19
cmatz3 0:253885b1f364 20 // flag for entry mode
cmatz3 0:253885b1f364 21 #define LCD_ENTRYLEFT 0x02
cmatz3 0:253885b1f364 22
cmatz3 0:253885b1f364 23 // flags for function set
cmatz3 0:253885b1f364 24 #define LCD_8BITMODE 0x10
cmatz3 0:253885b1f364 25 #define LCD_2LINE 0x08
cmatz3 0:253885b1f364 26 #define LCD_5x10DOTS 0x04
cmatz3 0:253885b1f364 27
cmatz3 1:40a3b6506c9f 28 /** Grove_LCD_RGB_Backlight Class.
cmatz3 1:40a3b6506c9f 29 * Used for connecting a Grove LCD RGB Backlit display
cmatz3 1:40a3b6506c9f 30 * to an mbed microcontroller via an I2C interface.
cmatz3 1:40a3b6506c9f 31 */
cmatz3 0:253885b1f364 32 class Grove_LCD_RGB_Backlight
cmatz3 0:253885b1f364 33 {
cmatz3 0:253885b1f364 34 public:
cmatz3 0:253885b1f364 35
cmatz3 1:40a3b6506c9f 36 /** Contructor. Creates an instance of the Grove_LCD_RGB_Backlight class.
cmatz3 1:40a3b6506c9f 37 * @param sda SDA pin on the mbed microcontroller which will be used to communicate with the display.
cmatz3 1:40a3b6506c9f 38 * @param scl SCL pin on the mbed microcontroller which will be used to communicate with the display.
cmatz3 1:40a3b6506c9f 39 */
cmatz3 0:253885b1f364 40 Grove_LCD_RGB_Backlight(PinName sda, PinName scl);
cmatz3 0:253885b1f364 41
cmatz3 0:253885b1f364 42
cmatz3 0:253885b1f364 43
cmatz3 2:5ce38ef7a7db 44 /** Set RGB color of backlight
cmatz3 1:40a3b6506c9f 45 * @param r Value for the red component of the RGB backlight (Between 0 and 255).
cmatz3 1:40a3b6506c9f 46 * @param g Value for the green component of the RGB backlight (Between 0 and 255).
cmatz3 1:40a3b6506c9f 47 * @param b Value for the blue component of the RGB backlight (Between 0 and 255).
cmatz3 1:40a3b6506c9f 48 */
cmatz3 0:253885b1f364 49 void setRGB(char r, char g, char b);
cmatz3 0:253885b1f364 50
cmatz3 1:40a3b6506c9f 51
cmatz3 1:40a3b6506c9f 52 /** Removes all of the text from the display.
cmatz3 1:40a3b6506c9f 53 */
cmatz3 1:40a3b6506c9f 54 void clear();
cmatz3 1:40a3b6506c9f 55
cmatz3 1:40a3b6506c9f 56 /**Prints text to the LCD display.
cmatz3 1:40a3b6506c9f 57 * @param *str Pointer to an array of characters which will be printed to the LCD screen.
cmatz3 1:40a3b6506c9f 58 */
cmatz3 1:40a3b6506c9f 59 void print(char *str);
cmatz3 1:40a3b6506c9f 60
cmatz3 1:40a3b6506c9f 61 /**Move cursor to specified location on the LCD screen.
cmatz3 1:40a3b6506c9f 62 * @param col Value for which column on the display the next text being printed will start at.
cmatz3 1:40a3b6506c9f 63 * @param row Value for which row on the display the next text being printed will be printed on.
cmatz3 1:40a3b6506c9f 64 */
cmatz3 1:40a3b6506c9f 65 void locate(char col, char row);
cmatz3 1:40a3b6506c9f 66
cmatz3 1:40a3b6506c9f 67
cmatz3 1:40a3b6506c9f 68 private:
cmatz3 1:40a3b6506c9f 69
cmatz3 0:253885b1f364 70 //Initialize device
cmatz3 0:253885b1f364 71 void init();
cmatz3 0:253885b1f364 72
cmatz3 0:253885b1f364 73 //Turn on display
cmatz3 0:253885b1f364 74 void displayOn();
cmatz3 0:253885b1f364 75
cmatz3 0:253885b1f364 76 //Send command to display
cmatz3 0:253885b1f364 77 void sendCommand(char value);
cmatz3 0:253885b1f364 78
cmatz3 0:253885b1f364 79 //Set register value
cmatz3 0:253885b1f364 80 void setReg(char addr, char val);
cmatz3 0:253885b1f364 81
cmatz3 0:253885b1f364 82 //MBED I2C object used to transfer data to LCD
cmatz3 0:253885b1f364 83 I2C i2c;
cmatz3 0:253885b1f364 84
cmatz3 0:253885b1f364 85 };