AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
Loading...
Searching...
No Matches
I2cLcd.h
Go to the documentation of this file.
1/*
2 I2cLcd.h - Tools for using an I2C-based LCD such as the
3 Adafruit RGB 16x2 LCD Shield .
4 For AVR ATMega328p (Arduino Uno) and ATMega2560 (Arduino Mega).
5 This is part of the AVRTools library.
6 Copyright (c) 2014 Igor Mikolic-Torreira. All right reserved.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22
37#ifndef I2cLcd_h
38#define I2cLcd_h
39
40#include <inttypes.h>
41#include "Writer.h"
42
43
44
45
57class I2cLcd : public Writer
58{
59public:
60
64 enum
65 {
68 kButton_Down = 0x04,
69 kButton_Up = 0x08,
70 kButton_Left = 0x10
71 };
72
73
77 enum
78 {
85 kBacklight_White = 0x7
86 };
87
88
92 I2cLcd();
93
94
102 int init();
103
104
108 void clear();
109
110
114 void home();
115
116
122 void displayTopRow( const char* str );
123
124
130 void displayBottomRow( const char* str );
131
132
136 void clearTopRow();
137
138
142 void clearBottomRow();
143
144
145
149 void displayOff();
150
151
155 void displayOn();
156
157
161 void blinkOff();
162
163
167 void blinkOn();
168
169
173 void cursorOff();
174
175
179 void cursorOn();
180
181
185 void scrollDisplayLeft();
186
187
191 void scrollDisplayRight();
192
193
197 void autoscrollOn();
198
199
203 void autoscrollOff();
204
205
212 void setCursor( uint8_t row, uint8_t col );
213
214
222 int setBacklight( uint8_t color );
223
224
230 void command( uint8_t cmd );
231
232
240 uint8_t readButtons();
241
242
243
252 virtual size_t write( char c );
253
254
263 virtual size_t write( const char* str );
264
265
275 virtual size_t write( const char* buffer, size_t size );
276
277
287 virtual size_t write( const uint8_t* buffer, size_t size );
288
289
294 virtual void flush();
295
296
297private:
298
299 enum
300 {
301 kWriteFourBitsSendChar = 0,
302 kWriteFourBitsSendCommand = 1
303 };
304
305 int initMCP23017();
306 int initHD44780U();
307 size_t write( uint8_t value );
308 int writeFourBitsToLcd( uint8_t value, uint8_t gpioB );
309 int sendCharOrCmdToLcd( uint8_t value, bool isCommand );
310
311 int sendCommand( uint8_t cmd )
312 {
313 return sendCharOrCmdToLcd( cmd, kWriteFourBitsSendCommand );
314 }
315
316 int sendCharToDisplay( uint8_t value )
317 {
318 return sendCharOrCmdToLcd( value, kWriteFourBitsSendChar );
319 }
320
321 uint8_t mDisplayControl;
322 uint8_t mDisplayMode;
323 uint8_t mCurrLine;
324 volatile uint8_t mI2cStatus;
325};
326
327#endif
This file provides a generic interface to outgoing data streams of any kind. It is designed around ho...
This class provides a high-level interface via I2C to an LCD such as those offered by AdaFruit and Sp...
Definition I2cLcd.h:58
void scrollDisplayLeft()
Scroll the display to the left.
Definition I2cLcd.cpp:528
void clearTopRow()
Clear the top row.
Definition I2cLcd.cpp:576
void autoscrollOn()
Turn on automatic scrolling of the display.
Definition I2cLcd.cpp:542
void scrollDisplayRight()
Scroll the display to the right.
Definition I2cLcd.cpp:535
void displayOn()
Turn the display on.
Definition I2cLcd.cpp:487
void blinkOn()
Blink the cursor.
Definition I2cLcd.cpp:519
void clear()
Clear the display (all rows, all columns).
Definition I2cLcd.cpp:449
virtual size_t write(char c)
Write a single character to the LCD at the current cursor location. This implements the pure virtual ...
Definition I2cLcd.cpp:602
void autoscrollOff()
Turn off automatic scrolling of the display.
Definition I2cLcd.cpp:550
I2cLcd()
Constructor simply initializes some internal bookkeeping.
Definition I2cLcd.cpp:210
uint8_t readButtons()
Read the state of the buttons associated with the LCD display.
Definition I2cLcd.cpp:686
void command(uint8_t cmd)
Pass a command to the LCD.
void displayBottomRow(const char *str)
Display a C-string on the bottom row.
Definition I2cLcd.cpp:567
@ kButton_Up
the Up button
Definition I2cLcd.h:69
@ kButton_Left
the Left button
Definition I2cLcd.h:70
@ kButton_Select
the Select button
Definition I2cLcd.h:66
@ kButton_Down
the Down button
Definition I2cLcd.h:68
@ kButton_Right
the Right button
Definition I2cLcd.h:67
void blinkOff()
Do not blink the cursor.
Definition I2cLcd.cpp:511
int setBacklight(uint8_t color)
Set the backlight to a given color. Set a black-and-white LCD display to White if you want to have a ...
Definition I2cLcd.cpp:659
void clearBottomRow()
Clear the bottom row.
Definition I2cLcd.cpp:583
void displayTopRow(const char *str)
Display a C-string on the top row.
Definition I2cLcd.cpp:559
@ kBacklight_Blue
Backlight blue.
Definition I2cLcd.h:83
@ kBacklight_Violet
Backlight violet.
Definition I2cLcd.h:84
@ kBacklight_Green
Backlight green.
Definition I2cLcd.h:81
@ kBacklight_Yellow
Backlight yellow.
Definition I2cLcd.h:80
@ kBacklight_Red
Backlight red.
Definition I2cLcd.h:79
@ kBacklight_White
Backlight white.
Definition I2cLcd.h:85
@ kBacklight_Teal
Backlight teal.
Definition I2cLcd.h:82
void cursorOn()
Display the cursor.
Definition I2cLcd.cpp:503
void displayOff()
Turn the display off.
Definition I2cLcd.cpp:479
void cursorOff()
Hide the cursor.
Definition I2cLcd.cpp:495
void setCursor(uint8_t row, uint8_t col)
Move the cursor the a particular row and column.
Definition I2cLcd.cpp:465
int init()
Initialize the I2cLcd object. This must be called before using the I2cLcd, or calling any of the othe...
Definition I2cLcd.cpp:219
virtual void flush()
This function does nothing. It simply implements the pure virtual function Writer::flush().
Definition I2cLcd.cpp:651
void home()
Move the cursor home (the top row, left column).
Definition I2cLcd.cpp:457
This is an abstract class defining a generic interface to write numbers and strings to a sequential s...
Definition Writer.h:64