As 1
As 1
As 1
Based
on the
work by
DFRobot
#include "LiquidCrystal_I2C.h"
#include <inttypes.h>
#include "Arduino.h"
send(value, Rs);
return 1;
#else
#include "WProgram.h"
send(value, Rs);
}
#endif
#include "Wire.h"
//
// 1. Display clear
// 2. Function set:
// N = 0; 1-line display
// D = 0; Display off
// C = 0; Cursor off
// B = 0; Blinking off
// I/D = 1; Increment by 1
// S = 0; No shift
//
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
// can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called).
_Addr = lcd_Addr;
_cols = lcd_cols;
_rows = lcd_rows;
_backlightval = LCD_NOBACKLIGHT;
void LiquidCrystal_I2C::oled_init(){
_oled = true;
init_priv();
void LiquidCrystal_I2C::init(){
init_priv();
void LiquidCrystal_I2C::init_priv()
Wire.begin();
if (lines > 1) {
_displayfunction |= LCD_2LINE;
_numlines = lines;
// for some 1 line displays you can select a 10 pixel high font
_displayfunction |= LCD_5x10DOTS;
// before sending commands. Arduino can turn on way befer 4.5V so we'll
wait 50
delay(50);
delay(1000);
//put the LCD into 4 bit mode
// figure 24, pg 46
// second try
// third go!
delayMicroseconds(150);
command(LCD_FUNCTIONSET | _displayfunction);
// clear it off
clear();
command(LCD_ENTRYMODESET | _displaymode);
home();
void LiquidCrystal_I2C::clear(){
if (_oled) setCursor(0,0);
void LiquidCrystal_I2C::home(){
}
void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
void LiquidCrystal_I2C::noDisplay() {
command(LCD_DISPLAYCONTROL | _displaycontrol);
void LiquidCrystal_I2C::display() {
_displaycontrol |= LCD_DISPLAYON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
void LiquidCrystal_I2C::noCursor() {
command(LCD_DISPLAYCONTROL | _displaycontrol);
void LiquidCrystal_I2C::cursor() {
_displaycontrol |= LCD_CURSORON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
void LiquidCrystal_I2C::noBlink() {
command(LCD_DISPLAYCONTROL | _displaycontrol);
void LiquidCrystal_I2C::blink() {
_displaycontrol |= LCD_BLINKON;
command(LCD_DISPLAYCONTROL | _displaycontrol);
void LiquidCrystal_I2C::scrollDisplayLeft(void) {
void LiquidCrystal_I2C::scrollDisplayRight(void) {
void LiquidCrystal_I2C::leftToRight(void) {
_displaymode |= LCD_ENTRYLEFT;
command(LCD_ENTRYMODESET | _displaymode);
void LiquidCrystal_I2C::rightToLeft(void) {
command(LCD_ENTRYMODESET | _displaymode);
void LiquidCrystal_I2C::autoscroll(void) {
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
command(LCD_ENTRYMODESET | _displaymode);
void LiquidCrystal_I2C::noAutoscroll(void) {
command(LCD_ENTRYMODESET | _displaymode);
write(charmap[i]);
write(pgm_read_byte_near(charmap++));
void LiquidCrystal_I2C::noBacklight(void) {
_backlightval=LCD_NOBACKLIGHT;
expanderWrite(0);
void LiquidCrystal_I2C::backlight(void) {
_backlightval=LCD_BACKLIGHT;
expanderWrite(0);
}
send(value, 0);
uint8_t highnib=value&0xf0;
uint8_t lownib=(value<<4)&0xf0;
write4bits((highnib)|mode);
write4bits((lownib)|mode);
}
void LiquidCrystal_I2C::write4bits(uint8_t value) {
expanderWrite(value);
pulseEnable(value);
Wire.beginTransmission(_Addr);
printIIC((int)(_data) | _backlightval);
Wire.endTransmission();
// Alias functions
void LiquidCrystal_I2C::cursor_on(){
cursor();
void LiquidCrystal_I2C::cursor_off(){
noCursor();
void LiquidCrystal_I2C::blink_on(){
blink();
void LiquidCrystal_I2C::blink_off(){
noBlink();
createChar(char_num, rows);
if(new_val){
//This function is not identical to the function used for "real" I2C
displays
print(c);
void LiquidCrystal_I2C::off(){}
void LiquidCrystal_I2C::on(){}