mirror of
https://github.com/fmalpartida/New-LiquidCrystal.git
synced 2026-07-27 19:56:57 +00:00
Added support and control methods to control backlight.
This commit is contained in:
+56
-31
@@ -2,7 +2,7 @@
|
||||
// Created by Francisco Malpartida on 20/08/11.
|
||||
// Copyright 2011 - Under creative commons license 3.0:
|
||||
// Attribution-ShareAlike CC BY-SA
|
||||
//LiquidCrystal
|
||||
//
|
||||
// This software is furnished "as is", without technical support, and with no
|
||||
// warranty, express or implied, as to its usefulness for any purpose.
|
||||
//
|
||||
@@ -38,7 +38,11 @@
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
#include "LiquidCrystal.h"
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// CONSTANT definitions
|
||||
// ---------------------------------------------------------------------------
|
||||
#define LCD_NOBACKLIGHT 0xFF
|
||||
|
||||
// STATIC helper functions
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -72,6 +76,37 @@ LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
init(LCD_4BIT, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PUBLIC METHODS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/************ low level data pushing commands **********/
|
||||
|
||||
// send
|
||||
void LiquidCrystal::send(uint8_t value, uint8_t mode)
|
||||
{
|
||||
digitalWrite( _rs_pin, mode );
|
||||
|
||||
// if there is a RW pin indicated, set it low to Write
|
||||
// ---------------------------------------------------
|
||||
if (_rw_pin != 255)
|
||||
{
|
||||
digitalWrite(_rw_pin, LOW);
|
||||
}
|
||||
|
||||
if (_displayfunction & LCD_8BITMODE)
|
||||
{
|
||||
writeNbits(value, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeNbits ( value >> 4, 4 );
|
||||
writeNbits ( value, 4 );
|
||||
}
|
||||
waitUsec ( EXEC_TIME ); // wait for the command to execute by the LCD
|
||||
}
|
||||
|
||||
// PRIVATE METHODS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -142,37 +177,10 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en
|
||||
{
|
||||
digitalWrite(_rw_pin, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
// PUBLIC METHODS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/************ low level data pushing commands **********/
|
||||
|
||||
// send
|
||||
void LiquidCrystal::send(uint8_t value, uint8_t mode)
|
||||
{
|
||||
digitalWrite( _rs_pin, mode );
|
||||
|
||||
// if there is a RW pin indicated, set it low to Write
|
||||
// ---------------------------------------------------
|
||||
if (_rw_pin != 255)
|
||||
{
|
||||
digitalWrite(_rw_pin, LOW);
|
||||
}
|
||||
|
||||
if (_displayfunction & LCD_8BITMODE)
|
||||
{
|
||||
writeNbits(value, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeNbits ( value >> 4, 4 );
|
||||
writeNbits ( value, 4 );
|
||||
}
|
||||
waitUsec ( EXEC_TIME ); // wait for the command to execute by the LCD
|
||||
// Initialise the backlight pin no nothing
|
||||
_backlightPin = LCD_NOBACKLIGHT;
|
||||
}
|
||||
|
||||
//
|
||||
// pulseEnable
|
||||
void LiquidCrystal::pulseEnable(void)
|
||||
@@ -194,3 +202,20 @@ void LiquidCrystal::writeNbits(uint8_t value, uint8_t numBits)
|
||||
}
|
||||
pulseEnable();
|
||||
}
|
||||
|
||||
//
|
||||
// setBackligh
|
||||
void LiquidCrystal::setBacklight ( uint8_t mode )
|
||||
{
|
||||
if ( _backlightPin != LCD_NOBACKLIGHT )
|
||||
{
|
||||
digitalWrite ( _backlightPin, mode );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// setBacklightPin
|
||||
void LiquidCrystal::setBacklightPin ( uint8_t pin )
|
||||
{
|
||||
_backlightPin = pin;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,27 @@ public:
|
||||
*/
|
||||
virtual void send(uint8_t value, uint8_t mode);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Switch-off the LCD backlight.
|
||||
@discussion Switch-off the LCD backlight, this method is not supported by
|
||||
the I2CLCDextraIO, it needs an extra IO pin to drive the LCD backlight.
|
||||
The setBacklightPin has to be called before setting the backlight for
|
||||
this method to work. @see setBacklightPin.
|
||||
|
||||
@param mode: backlight mode (HIGH|LOW)
|
||||
*/
|
||||
void setBacklight ( uint8_t mode );
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Sets the pin to control the backlight.
|
||||
@discussion Sets the pin in the device to control the backlight.
|
||||
|
||||
@param mode: backlight mode (HIGH|LOW)
|
||||
*/
|
||||
void setBacklightPin ( uint8_t pin );
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -119,6 +140,7 @@ private:
|
||||
uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
|
||||
uint8_t _enable_pin; // activated by a HIGH pulse.
|
||||
uint8_t _data_pins[8]; // Data pins.
|
||||
uint8_t _backlightPin; // Pin associated to control the LCD backlight
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+38
-37
@@ -38,6 +38,8 @@
|
||||
#include "I2CIO.h"
|
||||
#include "LiquidCrystal_I2C.h"
|
||||
|
||||
// CONSTANT definitions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// flags for backlight control
|
||||
#define LCD_NOBACKLIGHT 0x00
|
||||
@@ -103,6 +105,42 @@ LiquidCrystal_I2C::LiquidCrystal_I2C( uint8_t lcd_Addr, uint8_t En, uint8_t Rw,
|
||||
_data_pins[3] = ( 1 << d3 );
|
||||
}
|
||||
|
||||
// PUBLIC METHODS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// begin
|
||||
void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize)
|
||||
{
|
||||
|
||||
init(); // Initialise the I2C expander interface
|
||||
LCD::begin ( cols, lines, dotsize );
|
||||
}
|
||||
|
||||
|
||||
// User commands - users can expand this section
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Turn the (optional) backlight off/on
|
||||
void LiquidCrystal_I2C::setBacklight( uint8_t mode )
|
||||
{
|
||||
if ( mode == HIGH )
|
||||
{
|
||||
_backlightMask = _backlightPin & LCD_BACKLIGHT;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_backlightMask = _backlightPin & LCD_NOBACKLIGHT;
|
||||
}
|
||||
_i2cio.write( _backlightMask );
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::setBacklightPin ( uint8_t pin )
|
||||
{
|
||||
_backlightPin = ( 1 << pin );
|
||||
}
|
||||
|
||||
// PRIVATE METHODS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -125,43 +163,6 @@ int LiquidCrystal_I2C::init()
|
||||
return ( status );
|
||||
}
|
||||
|
||||
|
||||
// PUBLIC METHODS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// begin
|
||||
void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize)
|
||||
{
|
||||
|
||||
init(); // Initialise the I2C expander interface
|
||||
LCD::begin ( cols, lines, dotsize );
|
||||
}
|
||||
|
||||
|
||||
// User commands - users can expand this section
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Turn the (optional) backlight off/on
|
||||
void LiquidCrystal_I2C::setBacklight( uint8_t mode )
|
||||
{
|
||||
|
||||
if ( mode == HIGH )
|
||||
{
|
||||
_backlightMask = _backlightPin & LCD_BACKLIGHT;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_backlightMask = _backlightPin & LCD_NOBACKLIGHT;
|
||||
}
|
||||
_i2cio.write( _backlightMask );
|
||||
|
||||
}
|
||||
|
||||
// PRIVATE METHODS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// low level data pushing commands
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
||||
+12
-1
@@ -147,12 +147,23 @@ public:
|
||||
@function
|
||||
@abstract Switch-off the LCD backlight.
|
||||
@discussion Switch-off the LCD backlight, this method is not supported by
|
||||
the I2CLCDextraIO, it needs an extra IO pin to drive the LCD backlight
|
||||
the I2CLCDextraIO, it needs an extra IO pin to drive the LCD backlight.
|
||||
The setBacklightPin has to be called before setting the backlight for
|
||||
this method to work. @see setBacklightPin.
|
||||
|
||||
@param mode: backlight mode (HIGH|LOW)
|
||||
*/
|
||||
void setBacklight ( uint8_t mode );
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Sets the pin to control the backlight.
|
||||
@discussion Sets the pin in the device to control the backlight.
|
||||
|
||||
@param mode: backlight mode (HIGH|LOW)
|
||||
*/
|
||||
void setBacklightPin ( uint8_t pin );
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -171,3 +171,12 @@ void LiquidCrystal_SR::send(uint8_t value, uint8_t mode)
|
||||
shiftIt(mode | SR_EN_BIT | ((value >> 1) & 0x78)); // upper nibble
|
||||
shiftIt(mode | SR_EN_BIT | ((value << 3) & 0x78)); // lower nibble
|
||||
}
|
||||
|
||||
//
|
||||
// setBacklight
|
||||
void LiquidCrystal_SR::setBacklight ( uint8_t mode )
|
||||
{ }
|
||||
|
||||
|
||||
void LiquidCrystal_SR::setBacklightPin ( uint8_t pin )
|
||||
{ }
|
||||
|
||||
@@ -118,6 +118,28 @@ public:
|
||||
*/
|
||||
virtual void send(uint8_t value, uint8_t mode);
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Switch-off the LCD backlight.
|
||||
@discussion Switch-off the LCD backlight, this method is not supported by
|
||||
the I2CLCDextraIO, it needs an extra IO pin to drive the LCD backlight.
|
||||
The setBacklightPin has to be called before setting the backlight for
|
||||
this method to work. @see setBacklightPin.
|
||||
|
||||
@param mode: backlight mode (HIGH|LOW)
|
||||
*/
|
||||
void setBacklight ( uint8_t mode );
|
||||
|
||||
/*!
|
||||
@function
|
||||
@abstract Sets the pin to control the backlight.
|
||||
@discussion Sets the pin in the device to control the backlight.
|
||||
|
||||
@param mode: backlight mode (HIGH|LOW)
|
||||
*/
|
||||
void setBacklightPin ( uint8_t pin );
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user