Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AdaFruit_RGBLCDShield by
Adafruit_RGBLCDShield.h@2:01f8491ca9a5, 2014-08-30 (annotated)
- Committer:
- vtraveller
- Date:
- Sat Aug 30 16:29:58 2014 +0000
- Revision:
- 2:01f8491ca9a5
- Parent:
- 1:24ab601221e2
Updated with support for MCP9080 Adafruit sensor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vtraveller | 0:45264ce231f9 | 1 | /*************************************************** |
vtraveller | 0:45264ce231f9 | 2 | This is a library for the Adafruit RGB 16x2 LCD Shield |
vtraveller | 0:45264ce231f9 | 3 | Pick one up at the Adafruit shop! |
vtraveller | 0:45264ce231f9 | 4 | ---------> http://http://www.adafruit.com/products/714 |
vtraveller | 0:45264ce231f9 | 5 | |
vtraveller | 0:45264ce231f9 | 6 | The shield uses I2C to communicate, 2 pins are required to |
vtraveller | 0:45264ce231f9 | 7 | interface |
vtraveller | 0:45264ce231f9 | 8 | Adafruit invests time and resources providing this open source code, |
vtraveller | 0:45264ce231f9 | 9 | please support Adafruit and open-source hardware by purchasing |
vtraveller | 0:45264ce231f9 | 10 | products from Adafruit! |
vtraveller | 0:45264ce231f9 | 11 | |
vtraveller | 0:45264ce231f9 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. |
vtraveller | 0:45264ce231f9 | 13 | BSD license, all text above must be included in any redistribution |
vtraveller | 0:45264ce231f9 | 14 | ****************************************************/ |
vtraveller | 0:45264ce231f9 | 15 | |
vtraveller | 0:45264ce231f9 | 16 | #ifndef Adafruit_RGBLCDShield_h |
vtraveller | 0:45264ce231f9 | 17 | #define Adafruit_RGBLCDShield_h |
vtraveller | 0:45264ce231f9 | 18 | |
vtraveller | 0:45264ce231f9 | 19 | #include <inttypes.h> |
vtraveller | 0:45264ce231f9 | 20 | #include <MCP23017.h> |
vtraveller | 0:45264ce231f9 | 21 | |
vtraveller | 0:45264ce231f9 | 22 | // commands |
vtraveller | 0:45264ce231f9 | 23 | #define LCD_CLEARDISPLAY 0x01 |
vtraveller | 0:45264ce231f9 | 24 | #define LCD_RETURNHOME 0x02 |
vtraveller | 0:45264ce231f9 | 25 | #define LCD_ENTRYMODESET 0x04 |
vtraveller | 0:45264ce231f9 | 26 | #define LCD_DISPLAYCONTROL 0x08 |
vtraveller | 0:45264ce231f9 | 27 | #define LCD_CURSORSHIFT 0x10 |
vtraveller | 0:45264ce231f9 | 28 | #define LCD_FUNCTIONSET 0x20 |
vtraveller | 0:45264ce231f9 | 29 | #define LCD_SETCGRAMADDR 0x40 |
vtraveller | 0:45264ce231f9 | 30 | #define LCD_SETDDRAMADDR 0x80 |
vtraveller | 0:45264ce231f9 | 31 | |
vtraveller | 0:45264ce231f9 | 32 | // flags for display entry mode |
vtraveller | 0:45264ce231f9 | 33 | #define LCD_ENTRYRIGHT 0x00 |
vtraveller | 0:45264ce231f9 | 34 | #define LCD_ENTRYLEFT 0x02 |
vtraveller | 0:45264ce231f9 | 35 | #define LCD_ENTRYSHIFTINCREMENT 0x01 |
vtraveller | 0:45264ce231f9 | 36 | #define LCD_ENTRYSHIFTDECREMENT 0x00 |
vtraveller | 0:45264ce231f9 | 37 | |
vtraveller | 0:45264ce231f9 | 38 | // flags for display on/off control |
vtraveller | 0:45264ce231f9 | 39 | #define LCD_DISPLAYON 0x04 |
vtraveller | 0:45264ce231f9 | 40 | #define LCD_DISPLAYOFF 0x00 |
vtraveller | 0:45264ce231f9 | 41 | #define LCD_CURSORON 0x02 |
vtraveller | 0:45264ce231f9 | 42 | #define LCD_CURSOROFF 0x00 |
vtraveller | 0:45264ce231f9 | 43 | #define LCD_BLINKON 0x01 |
vtraveller | 0:45264ce231f9 | 44 | #define LCD_BLINKOFF 0x00 |
vtraveller | 0:45264ce231f9 | 45 | |
vtraveller | 0:45264ce231f9 | 46 | // flags for display/cursor shift |
vtraveller | 0:45264ce231f9 | 47 | #define LCD_DISPLAYMOVE 0x08 |
vtraveller | 0:45264ce231f9 | 48 | #define LCD_CURSORMOVE 0x00 |
vtraveller | 0:45264ce231f9 | 49 | #define LCD_MOVERIGHT 0x04 |
vtraveller | 0:45264ce231f9 | 50 | #define LCD_MOVELEFT 0x00 |
vtraveller | 0:45264ce231f9 | 51 | |
vtraveller | 0:45264ce231f9 | 52 | // flags for function set |
vtraveller | 0:45264ce231f9 | 53 | #define LCD_8BITMODE 0x10 |
vtraveller | 0:45264ce231f9 | 54 | #define LCD_4BITMODE 0x00 |
vtraveller | 0:45264ce231f9 | 55 | #define LCD_2LINE 0x08 |
vtraveller | 0:45264ce231f9 | 56 | #define LCD_1LINE 0x00 |
vtraveller | 0:45264ce231f9 | 57 | #define LCD_5x10DOTS 0x04 |
vtraveller | 0:45264ce231f9 | 58 | #define LCD_5x8DOTS 0x00 |
vtraveller | 0:45264ce231f9 | 59 | |
vtraveller | 0:45264ce231f9 | 60 | #define BUTTON_UP 0x08 |
vtraveller | 0:45264ce231f9 | 61 | #define BUTTON_DOWN 0x04 |
vtraveller | 0:45264ce231f9 | 62 | #define BUTTON_LEFT 0x10 |
vtraveller | 0:45264ce231f9 | 63 | #define BUTTON_RIGHT 0x02 |
vtraveller | 0:45264ce231f9 | 64 | #define BUTTON_SELECT 0x01 |
vtraveller | 0:45264ce231f9 | 65 | |
vtraveller | 0:45264ce231f9 | 66 | class Adafruit_RGBLCDShield |
vtraveller | 0:45264ce231f9 | 67 | : public Serial // MBED was Print |
vtraveller | 0:45264ce231f9 | 68 | { |
vtraveller | 0:45264ce231f9 | 69 | public: |
vtraveller | 0:45264ce231f9 | 70 | // Updated constructor |
vtraveller | 0:45264ce231f9 | 71 | Adafruit_RGBLCDShield(MCP23017 & inMCP); |
vtraveller | 2:01f8491ca9a5 | 72 | Adafruit_RGBLCDShield |
vtraveller | 2:01f8491ca9a5 | 73 | ( |
vtraveller | 2:01f8491ca9a5 | 74 | MCP23017 & inMCP, |
vtraveller | 2:01f8491ca9a5 | 75 | uint8_t inRs, |
vtraveller | 2:01f8491ca9a5 | 76 | uint8_t inRw, |
vtraveller | 2:01f8491ca9a5 | 77 | uint8_t inEn, |
vtraveller | 2:01f8491ca9a5 | 78 | uint8_t inD4, |
vtraveller | 2:01f8491ca9a5 | 79 | uint8_t inD5, |
vtraveller | 2:01f8491ca9a5 | 80 | uint8_t inD6, |
vtraveller | 2:01f8491ca9a5 | 81 | uint8_t inD7 |
vtraveller | 2:01f8491ca9a5 | 82 | ); |
vtraveller | 2:01f8491ca9a5 | 83 | |
vtraveller | 0:45264ce231f9 | 84 | |
vtraveller | 0:45264ce231f9 | 85 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, |
vtraveller | 0:45264ce231f9 | 86 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, |
vtraveller | 0:45264ce231f9 | 87 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); |
vtraveller | 0:45264ce231f9 | 88 | |
vtraveller | 0:45264ce231f9 | 89 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); |
vtraveller | 1:24ab601221e2 | 90 | uint8_t lines(); |
vtraveller | 0:45264ce231f9 | 91 | |
vtraveller | 0:45264ce231f9 | 92 | void clear(); |
vtraveller | 0:45264ce231f9 | 93 | void home(); |
vtraveller | 0:45264ce231f9 | 94 | |
vtraveller | 0:45264ce231f9 | 95 | void noDisplay(); |
vtraveller | 0:45264ce231f9 | 96 | void display(); |
vtraveller | 0:45264ce231f9 | 97 | void noBlink(); |
vtraveller | 0:45264ce231f9 | 98 | void blink(); |
vtraveller | 0:45264ce231f9 | 99 | void noCursor(); |
vtraveller | 0:45264ce231f9 | 100 | void cursor(); |
vtraveller | 0:45264ce231f9 | 101 | void scrollDisplayLeft(); |
vtraveller | 0:45264ce231f9 | 102 | void scrollDisplayRight(); |
vtraveller | 0:45264ce231f9 | 103 | void leftToRight(); |
vtraveller | 0:45264ce231f9 | 104 | void rightToLeft(); |
vtraveller | 0:45264ce231f9 | 105 | void autoscroll(); |
vtraveller | 0:45264ce231f9 | 106 | void noAutoscroll(); |
vtraveller | 0:45264ce231f9 | 107 | |
vtraveller | 0:45264ce231f9 | 108 | // only if using backpack |
vtraveller | 0:45264ce231f9 | 109 | void setBacklight(uint8_t status); |
vtraveller | 0:45264ce231f9 | 110 | |
vtraveller | 0:45264ce231f9 | 111 | void createChar(uint8_t, uint8_t[]); |
vtraveller | 0:45264ce231f9 | 112 | void setCursor(uint8_t, uint8_t); |
vtraveller | 0:45264ce231f9 | 113 | #if ARDUINO >= 100 |
vtraveller | 0:45264ce231f9 | 114 | //virtual size_t write(uint8_t); |
vtraveller | 0:45264ce231f9 | 115 | #else |
vtraveller | 0:45264ce231f9 | 116 | //virtual void write(uint8_t); |
vtraveller | 0:45264ce231f9 | 117 | virtual int _putc(int c); |
vtraveller | 0:45264ce231f9 | 118 | #endif |
vtraveller | 0:45264ce231f9 | 119 | void command(uint8_t); |
vtraveller | 0:45264ce231f9 | 120 | uint8_t readButtons(); |
vtraveller | 0:45264ce231f9 | 121 | |
vtraveller | 0:45264ce231f9 | 122 | private: |
vtraveller | 0:45264ce231f9 | 123 | void send(uint8_t, uint8_t); |
vtraveller | 0:45264ce231f9 | 124 | void write4bits(uint8_t); |
vtraveller | 0:45264ce231f9 | 125 | void write8bits(uint8_t); |
vtraveller | 0:45264ce231f9 | 126 | void pulseEnable(); |
vtraveller | 0:45264ce231f9 | 127 | void _digitalWrite(uint8_t, uint8_t); |
vtraveller | 0:45264ce231f9 | 128 | void _pinMode(uint8_t, uint8_t); |
vtraveller | 0:45264ce231f9 | 129 | |
vtraveller | 0:45264ce231f9 | 130 | uint8_t _rs_pin; // LOW: command. HIGH: character. |
vtraveller | 0:45264ce231f9 | 131 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. |
vtraveller | 0:45264ce231f9 | 132 | uint8_t _enable_pin; // activated by a HIGH pulse. |
vtraveller | 0:45264ce231f9 | 133 | uint8_t _data_pins[8]; |
vtraveller | 0:45264ce231f9 | 134 | uint8_t _button_pins[5]; |
vtraveller | 0:45264ce231f9 | 135 | uint8_t _displayfunction; |
vtraveller | 0:45264ce231f9 | 136 | uint8_t _displaycontrol; |
vtraveller | 0:45264ce231f9 | 137 | uint8_t _displaymode; |
vtraveller | 0:45264ce231f9 | 138 | |
vtraveller | 0:45264ce231f9 | 139 | uint8_t _initialized; |
vtraveller | 0:45264ce231f9 | 140 | |
vtraveller | 0:45264ce231f9 | 141 | uint8_t _numlines,_currline; |
vtraveller | 0:45264ce231f9 | 142 | |
vtraveller | 0:45264ce231f9 | 143 | uint8_t _i2cAddr; |
vtraveller | 0:45264ce231f9 | 144 | MCP23017 _i2c; |
vtraveller | 0:45264ce231f9 | 145 | }; |
vtraveller | 0:45264ce231f9 | 146 | |
vtraveller | 0:45264ce231f9 | 147 | #endif |