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.
Adafruit_RGBLCDShield.h@0:45264ce231f9, 2014-08-03 (annotated)
- Committer:
- vtraveller
- Date:
- Sun Aug 03 15:03:47 2014 +0000
- Revision:
- 0:45264ce231f9
- Child:
- 1:24ab601221e2
Moved AdaFruit_RGBShield to a library
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 | 0:45264ce231f9 | 72 | |
| vtraveller | 0:45264ce231f9 | 73 | void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, |
| vtraveller | 0:45264ce231f9 | 74 | uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, |
| vtraveller | 0:45264ce231f9 | 75 | uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); |
| vtraveller | 0:45264ce231f9 | 76 | |
| vtraveller | 0:45264ce231f9 | 77 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); |
| vtraveller | 0:45264ce231f9 | 78 | |
| vtraveller | 0:45264ce231f9 | 79 | void clear(); |
| vtraveller | 0:45264ce231f9 | 80 | void home(); |
| vtraveller | 0:45264ce231f9 | 81 | |
| vtraveller | 0:45264ce231f9 | 82 | void noDisplay(); |
| vtraveller | 0:45264ce231f9 | 83 | void display(); |
| vtraveller | 0:45264ce231f9 | 84 | void noBlink(); |
| vtraveller | 0:45264ce231f9 | 85 | void blink(); |
| vtraveller | 0:45264ce231f9 | 86 | void noCursor(); |
| vtraveller | 0:45264ce231f9 | 87 | void cursor(); |
| vtraveller | 0:45264ce231f9 | 88 | void scrollDisplayLeft(); |
| vtraveller | 0:45264ce231f9 | 89 | void scrollDisplayRight(); |
| vtraveller | 0:45264ce231f9 | 90 | void leftToRight(); |
| vtraveller | 0:45264ce231f9 | 91 | void rightToLeft(); |
| vtraveller | 0:45264ce231f9 | 92 | void autoscroll(); |
| vtraveller | 0:45264ce231f9 | 93 | void noAutoscroll(); |
| vtraveller | 0:45264ce231f9 | 94 | |
| vtraveller | 0:45264ce231f9 | 95 | // only if using backpack |
| vtraveller | 0:45264ce231f9 | 96 | void setBacklight(uint8_t status); |
| vtraveller | 0:45264ce231f9 | 97 | |
| vtraveller | 0:45264ce231f9 | 98 | void createChar(uint8_t, uint8_t[]); |
| vtraveller | 0:45264ce231f9 | 99 | void setCursor(uint8_t, uint8_t); |
| vtraveller | 0:45264ce231f9 | 100 | #if ARDUINO >= 100 |
| vtraveller | 0:45264ce231f9 | 101 | //virtual size_t write(uint8_t); |
| vtraveller | 0:45264ce231f9 | 102 | #else |
| vtraveller | 0:45264ce231f9 | 103 | //virtual void write(uint8_t); |
| vtraveller | 0:45264ce231f9 | 104 | virtual int _putc(int c); |
| vtraveller | 0:45264ce231f9 | 105 | #endif |
| vtraveller | 0:45264ce231f9 | 106 | void command(uint8_t); |
| vtraveller | 0:45264ce231f9 | 107 | uint8_t readButtons(); |
| vtraveller | 0:45264ce231f9 | 108 | |
| vtraveller | 0:45264ce231f9 | 109 | private: |
| vtraveller | 0:45264ce231f9 | 110 | void send(uint8_t, uint8_t); |
| vtraveller | 0:45264ce231f9 | 111 | void write4bits(uint8_t); |
| vtraveller | 0:45264ce231f9 | 112 | void write8bits(uint8_t); |
| vtraveller | 0:45264ce231f9 | 113 | void pulseEnable(); |
| vtraveller | 0:45264ce231f9 | 114 | void _digitalWrite(uint8_t, uint8_t); |
| vtraveller | 0:45264ce231f9 | 115 | void _pinMode(uint8_t, uint8_t); |
| vtraveller | 0:45264ce231f9 | 116 | |
| vtraveller | 0:45264ce231f9 | 117 | uint8_t _rs_pin; // LOW: command. HIGH: character. |
| vtraveller | 0:45264ce231f9 | 118 | uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. |
| vtraveller | 0:45264ce231f9 | 119 | uint8_t _enable_pin; // activated by a HIGH pulse. |
| vtraveller | 0:45264ce231f9 | 120 | uint8_t _data_pins[8]; |
| vtraveller | 0:45264ce231f9 | 121 | uint8_t _button_pins[5]; |
| vtraveller | 0:45264ce231f9 | 122 | uint8_t _displayfunction; |
| vtraveller | 0:45264ce231f9 | 123 | uint8_t _displaycontrol; |
| vtraveller | 0:45264ce231f9 | 124 | uint8_t _displaymode; |
| vtraveller | 0:45264ce231f9 | 125 | |
| vtraveller | 0:45264ce231f9 | 126 | uint8_t _initialized; |
| vtraveller | 0:45264ce231f9 | 127 | |
| vtraveller | 0:45264ce231f9 | 128 | uint8_t _numlines,_currline; |
| vtraveller | 0:45264ce231f9 | 129 | |
| vtraveller | 0:45264ce231f9 | 130 | uint8_t _i2cAddr; |
| vtraveller | 0:45264ce231f9 | 131 | MCP23017 _i2c; |
| vtraveller | 0:45264ce231f9 | 132 | }; |
| vtraveller | 0:45264ce231f9 | 133 | |
| vtraveller | 0:45264ce231f9 | 134 | #endif |