Skip to content

Instantly share code, notes, and snippets.

@DylanKnevitt
Last active August 29, 2015 14:11
Show Gist options
  • Save DylanKnevitt/2f9015f2d6b0016c0e16 to your computer and use it in GitHub Desktop.
Save DylanKnevitt/2f9015f2d6b0016c0e16 to your computer and use it in GitHub Desktop.
j5 LCD Documentation

The LCD class constructs an object that represents an LCD Display.

Parameters

  • options An object of property parameters
Property Name Type Value(s) Description Required
pins Object ```js { rs, en, d4, d5, d6, d7 } ``` Sets the values of the rs, en, d4, d5, d6 and d7 pins. yes

Shape

{
  board: A reference to the board object the Led is attached to
  id: A user definable id value. Defaults to null
  bitmode: Defines the bitmode of the LCD display. Options are 4bit and 8bit.
  lines: The number of lines that the LCD display supports. Defaults to 2.
  rows: The number of rows that the LCD display supports. Defaults to 2.
  cols: The number of columns that the LCD display contains. Defaults to 16.
  dots: The number of dots per column. Defaults to 5x8.
  pins : the object containing the pin values for rs, en, d4, d5, d6, d7
}

Usage

var five = require("johnny-five"), 
    board = new five.Board();

board.on("ready", function() {

  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });

  lcd.on("ready", function(){
    lcd.clear();
    lcd.home();
    lcd.print("Hello");
  });
  });

API

  • print(message,opts) prints the string 'message' to the LCD display at the cursor's current position
  • if opts.dontProcessSpecials is set to true, it will not print out any special characters created by the useChar(charCode) function.
  // Example without dontProcessSpecials
   var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
   lcd.print('Bleep bloop');
  
  // Example with dontProcessSpecials
  lcd.useChar("heart");
  lcd.print('Hello :heart:',{ dontProcessSpecials : false });
  • useChar(charCode) Creates the character in LCD memory and adds character to current LCD character map
 var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
 lcd.useChar("heart");
 lcd.print('Hello :heart:');
  • clear() Clears all text on the LCD.
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.print('Bleep bloop');
  lcd.clear();
  • setCursor(x,y) Sets the cursor the the position <x,y>
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.setCursor(0,0).print('Bleep'); //The starting position of the LCD display
  lcd.setCursor(0,1).print('Bloop'); //The second line, first character of the LCD display
  • home() Sets the cursor the the position <0,0>
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.setCursor(0,1).print('Bloop');  //The second line, first character of the LCD display
  lcd.home().print('Bleep'); //The second line, first character of the LCD display
  • display() Shows the characters on the LCD display
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.display().print('Bleep Bloop');
  • noDisplay() Shows the characters on the LCD display
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.noDisplay().print('Bleep Bloop'); //You will not see this text on the LCD display
  • blink() This causes the cursor to show and blink
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.blink().print('Bleep Bloop');
  • noBlink() This causes the cursor to stop blinking
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.noBlink().print('Bleep Bloop');
  • autoscroll() Turns on automatic scrolling of the LCD. This causes each character output to the display to push previous characters - over by one space
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.autoscroll().print('Bloop').print('Bleep');
  • noAutoscroll() Turns off automatic scrolling of the LCD.
  var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] });
  lcd.noAutoscroll().print('Bloop').print('Bleep');

Events

  • ready The "ready" event is emitted whenever the value of the LCD has completed setup and is ready for use.
@rwaldron
Copy link

This looks great!

I few bits of feedback and nitpicks ;)

  • Double quotes please <3
  • For the example code in the method descriptions, you can omit the var lcd = new five.LCD({ pins: [ 2,3,4,5,11,12 ] }); in each of them.
  • The "ready" event has gone away, the LCD blocks for an imperceptible amount of time while it's initializing (but never again after that)
  • Let's write useChar(charCode) as useChar(name) (I don't want it to be confused for actual char codes, ie. String.fromCharCode(...)
  • Currently, pins option can only be an array, but I will fix that to match other classes that allow both an array or object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment