Library to operate Grove-LCD RGB Backlight v4.0

Committer:
nono411
Date:
Mon Apr 15 07:44:45 2019 +0000
Revision:
0:fb21134ce1b9
RGB LCD Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nono411 0:fb21134ce1b9 1 /*
nono411 0:fb21134ce1b9 2 rgb_lcd library
nono411 0:fb21134ce1b9 3 Created by: Isaac Maximiliano Martinez Govea
nono411 0:fb21134ce1b9 4 15/04/2019
nono411 0:fb21134ce1b9 5 */
nono411 0:fb21134ce1b9 6
nono411 0:fb21134ce1b9 7 #ifndef RGB_LCD_H
nono411 0:fb21134ce1b9 8 #define RGB_LCD_H
nono411 0:fb21134ce1b9 9
nono411 0:fb21134ce1b9 10 /* Constants */
nono411 0:fb21134ce1b9 11 //Addresses I2C
nono411 0:fb21134ce1b9 12 #define LCD_ADDRESS (0x7C)
nono411 0:fb21134ce1b9 13 #define RGB_ADDRESS (0xC4)
nono411 0:fb21134ce1b9 14
nono411 0:fb21134ce1b9 15 //Registres de la couleur
nono411 0:fb21134ce1b9 16 #define REG_MODE1 0x00
nono411 0:fb21134ce1b9 17 #define REG_MODE2 0X01
nono411 0:fb21134ce1b9 18 #define REG_OUTPUT 0x08
nono411 0:fb21134ce1b9 19
nono411 0:fb21134ce1b9 20 #define REG_RED 0x04
nono411 0:fb21134ce1b9 21 #define REG_GREEN 0x03
nono411 0:fb21134ce1b9 22 #define REG_BLUE 0x02
nono411 0:fb21134ce1b9 23
nono411 0:fb21134ce1b9 24 //COMMANDES LCD
nono411 0:fb21134ce1b9 25 #define LCD_FUNCTIONSET 0x20
nono411 0:fb21134ce1b9 26 #define LCD_ENTRYMODESET 0x04
nono411 0:fb21134ce1b9 27 #define LCD_DISPLAYCONTROL 0x08
nono411 0:fb21134ce1b9 28 #define LCD_CLEARDISPLAY 0x01
nono411 0:fb21134ce1b9 29
nono411 0:fb21134ce1b9 30 //Flags
nono411 0:fb21134ce1b9 31 #define LCD_2LINE 0x08
nono411 0:fb21134ce1b9 32 #define LCD_5X10DOTS 0x04
nono411 0:fb21134ce1b9 33 #define LCD_5X8DOTS 0x00
nono411 0:fb21134ce1b9 34 #define LCD_DISPLAYON 0x04
nono411 0:fb21134ce1b9 35 #define LCD_CURSOROFF 0x00
nono411 0:fb21134ce1b9 36 #define LCD_BLINKOFF 0x00
nono411 0:fb21134ce1b9 37 #define LCD_ENTRYLEFT 0x02
nono411 0:fb21134ce1b9 38 #define LCD_ENTRYSHIFTDECREMENT 0x00
nono411 0:fb21134ce1b9 39
nono411 0:fb21134ce1b9 40 #include "mbed.h"
nono411 0:fb21134ce1b9 41
nono411 0:fb21134ce1b9 42 class rgb_lcd : public Stream{
nono411 0:fb21134ce1b9 43 private:
nono411 0:fb21134ce1b9 44 I2C *i2c;
nono411 0:fb21134ce1b9 45 uint8_t _displayfunction;
nono411 0:fb21134ce1b9 46 uint8_t _displaycontrol;
nono411 0:fb21134ce1b9 47 uint8_t _displaymode;
nono411 0:fb21134ce1b9 48
nono411 0:fb21134ce1b9 49 /*
nono411 0:fb21134ce1b9 50 Local comunication fonctions
nono411 0:fb21134ce1b9 51 */
nono411 0:fb21134ce1b9 52 void setReg(uint8_t reg, uint8_t value); // Communication with the RGB driver
nono411 0:fb21134ce1b9 53 void command(uint8_t comm); // Communication with the LCD driver
nono411 0:fb21134ce1b9 54
nono411 0:fb21134ce1b9 55 void write(uint8_t value); // Communication with the print register of the LCD
nono411 0:fb21134ce1b9 56 void i2c_send_byteS(uint8_t *data, uint8_t len); // Communication I2C
nono411 0:fb21134ce1b9 57 protected:
nono411 0:fb21134ce1b9 58 /*
nono411 0:fb21134ce1b9 59 We overdrive these functions to get acces to the function printf
nono411 0:fb21134ce1b9 60 */
nono411 0:fb21134ce1b9 61 virtual int _putc(int c);
nono411 0:fb21134ce1b9 62 virtual int _getc();
nono411 0:fb21134ce1b9 63 public:
nono411 0:fb21134ce1b9 64 rgb_lcd(I2C* i2c_bus);
nono411 0:fb21134ce1b9 65
nono411 0:fb21134ce1b9 66 /*
nono411 0:fb21134ce1b9 67 User Fonctions
nono411 0:fb21134ce1b9 68 */
nono411 0:fb21134ce1b9 69 void begin(); // Initialize the LCD
nono411 0:fb21134ce1b9 70 void setRGB(uint8_t r, uint8_t g, uint8_t b); // Set backlight-color
nono411 0:fb21134ce1b9 71 void setCursor(uint8_t col, uint8_t row); // Set cursor position
nono411 0:fb21134ce1b9 72 void display(); // Display text
nono411 0:fb21134ce1b9 73 void clear(); // Clear display
nono411 0:fb21134ce1b9 74
nono411 0:fb21134ce1b9 75 void test_rgb();
nono411 0:fb21134ce1b9 76 };
nono411 0:fb21134ce1b9 77
nono411 0:fb21134ce1b9 78 #endif