Node Library for using adafruit i2c rgb lcd pi plate
npm install adafruit-i2c-lcdnpm i npm -g`)
Note: This module is compatible with Sainsmart 1602 I2C, see Compatibility
Usage
1. read the i2c-bus documentation how to setup your raspberry pi.
2. add dependency using `npm install adafruit-i2c-lcd --save`
3. Copy and run one of the examples from the examples directory. Maybe you have to run them as root.
$3
`javascript
var LCDPLATE, lcd;
LCDPLATE = require('adafruit-i2c-lcd').plate;
lcd = new LCDPLATE(1, 0x20);
lcd.backlight(lcd.colors.RED);
lcd.message('Hello World!');
lcd.on('button_change', function(button) {
lcd.clear();
lcd.message('Button changed:\n' + lcd.buttonName(button));
});
`
API
- [LCDPLATE(device:String,address:Number,[pollInterval:Number])](#lcdplatedevicestringaddressnumberpollintervalnumber)
- LCDPLATE.clear()
- LCDPLATE.close()
- LCDPLATE.backlight(color:Number)
- [LCDPLATE.message(text:String,[clear:boolean])](#lcdplatemessagetextstring-booleanclear)
- [LCDPLATE.createChar(index:Number, pattern:byte[])](#lcdplatecreatecharindexnumber-patternbyte)
- LCDPLATE.buttonState():Number
- LCDPLATE.buttonName(val:Number):String
$3
Setting up a new LCDPLATE.
- device: Device name, e.g. '/dev/i2c-1'
- address: Address of the i2c panel, e.g. 0x20
- pollInterval: optional. Set the poll interval for the buttons to x ms. Use pollInterval=-1 to disable polling. (Buttons will not work)
$3
Clear the LCD, remove all text.
$3
Close the LCD plate. Use this to stop the polling.
$3
Set the backlight of the LCD to the given color. You can use predefined colors from the LCDPLATE class:
LCDPLATE.colors = [OFF, RED, GREEN, BLUE, YELLOW, TEAL, VIOLET, WHITE, ON]
$3
Add the text on the LCD. Use \n as line feed. Only the first two lines will be sent to the display.
If parameter clear is given and true only the text is shown, previous content on the lcd will be cleared.
$3
Defines custom characters. Index must be between 0 and 7. Pattern is the pattern of your character, must contain exactly 8 bytes.
E.g. you can easyly design your custom character at http://www.quinapalus.com/hd44780udg.html to show your custom character use eg. lcd.message('\x01').
Example:
`javascript
lcd.createChar(1, [0,0,10,31,31,14,4,0]);
lcd.createChar(2, [0,4,10,17,17,10,4,0]);
lcd.clear();
lcd.backlight(lcd.colors.RED);
lcd.message('I\x01 n\x02de.js', true);
`
$3
Returns the pressed buttons as a number. Use bitmasks to mask out the state of the desired button. See LCDPLATE.buttons for button values.
$3
Returns the name, e.g. 'SELECT' to a button number. See LCDPLATE.buttons for button values.
Events
$3
Fires if a button is pressed or released.
Parameters:
* button: the button, See LCDPLATE.buttons for button values.
$3
`javascript
lcd.on('button_change', function(button) {
lcd.clear();
lcd.message('Button changed:\n' + lcd.buttonName(button));
});
`
$3
Fires if a button is released.
Parameters:
* button: the button, See LCDPLATE.buttons for button values.
$3
Fires if a button is pressed.
Parameters:
* button: the button, See LCDPLATE.buttons for button values.
Compatibility
This library is compatible with the Sainsmart 1602 I2C (SKU: 20-011-221)
with some notable exceptions. This clone has a blue backlight and an
RGB LED on-board.
* The LCDPLATE.backlight() function
changes the RGB LED rather than the backlight.
* The backlight on the LCD is connected to GPA5, which is the sixth (6th)
bit of port A. It can be set on or off directly in your client code.
`javascript
lcd.sendBytes(0, 0x1F); // Sainsmart 1602 I2C backlight on
lcd.sendBytes(0, 0x3F); // Sainsmart 1602 I2C backlight off
``