hArduino-0.6: Control your Arduino board from Haskell.

Stabilityexperimental
Maintainererkokl@gmail.com
Safe HaskellNone

System.Hardware.Arduino.Parts.LCD

Contents

Description

LCD (Liquid Crystal Display) parts supported by hArduino. The Haskell code below has partly been implemented following the Arduino LiquidCrystal project source code: http://code.google.com/p/arduino/source/browse/trunk/libraries/LiquidCrystal/

The Hitachi44780 data sheet is at: http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf

For an example program using this library, see System.Hardware.Arduino.SamplePrograms.LCD.

Synopsis

LCD types and registration

data LCDController Source

Hitachi LCD controller: See: http://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller. We model only the 4-bit variant, with RS and EN lines only. (The most common Arduino usage.) The data sheet can be seen at: http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf.

Constructors

Hitachi44780 

Fields

lcdRS :: Pin

Hitachi pin 4: Register-select

lcdEN :: Pin

Hitachi pin 6: Enable

lcdD4 :: Pin

Hitachi pin 11: Data line 4

lcdD5 :: Pin

Hitachi pin 12: Data line 5

lcdD6 :: Pin

Hitachi pin 13: Data line 6

lcdD7 :: Pin

Hitachi pin 14: Data line 7

lcdRows :: Int

Number of rows (typically 1 or 2, upto 4)

lcdCols :: Int

Number of cols (typically 16 or 20, upto 40)

dotMode5x10 :: Bool

Set to True if 5x10 dots are used

Instances

lcdRegister :: LCDController -> Arduino LCDSource

Register an LCD controller. When registration is complete, the LCD will be initialized so that:

Writing text on the LCD

lcdClear :: LCD -> Arduino ()Source

Clear the LCD

lcdWrite :: LCD -> String -> Arduino ()Source

Write a string on the LCD at the current cursor position

Moving the cursor

lcdHome :: LCD -> Arduino ()Source

Send the cursor to home position

lcdSetCursor :: LCD -> (Int, Int) -> Arduino ()Source

Set the cursor location. The pair of arguments is the new column and row numbers respectively:

  • The first value is the column, the second is the row. (This is counter-intuitive, but is in line with what the standard Arduino programmers do, so we follow the same convention.)
  • Counting starts at 0 (both for column and row no)
  • If the new location is out-of-bounds of your LCD, we will put it the cursor to the closest possible location on the LCD.

Scrolling

lcdAutoScrollOn :: LCD -> Arduino ()Source

Turn on auto-scrolling. In the context of the Hitachi44780 controller, this means that each time a letter is added, all the text is moved one space to the left. This can be confusing at first: It does not mean that your strings will continuously scroll: It just means that if you write a string whose length exceeds the column-count of your LCD, then you'll see the tail-end of it. (Of course, this will create a scrolling effect as the string is being printed character by character.)

Having said that, it is easy to program a scrolling string program: Simply write your string by calling lcdWrite, and then use the lcdScrollDisplayLeft and lcdScrollDisplayRight functions with appropriate delays to simulate the scrolling.

lcdAutoScrollOff :: LCD -> Arduino ()Source

Turn off auto-scrolling. See the comments for lcdAutoScrollOn for details. When turned off (which is the default), you will not see the characters at the end of your strings that do not fit into the display.

lcdScrollDisplayLeft :: LCD -> Arduino ()Source

Scroll the display to the left by 1 character. Project idea: Using a tilt sensor, scroll the contents of the display left/right depending on the tilt.

lcdScrollDisplayRight :: LCD -> Arduino ()Source

Scroll the display to the right by 1 character

Display properties

lcdLeftToRight :: LCD -> Arduino ()Source

Set writing direction: Left to Right

lcdRightToLeft :: LCD -> Arduino ()Source

Set writing direction: Right to Left

lcdBlinkOn :: LCD -> Arduino ()Source

Blink the cursor

lcdBlinkOff :: LCD -> Arduino ()Source

Do not blink the cursor

lcdCursorOn :: LCD -> Arduino ()Source

Show the cursor

lcdCursorOff :: LCD -> Arduino ()Source

Hide the cursor. Note that a blinking cursor cannot be hidden, you must first turn off blinking.

lcdDisplayOn :: LCD -> Arduino ()Source

Turn the display on

lcdDisplayOff :: LCD -> Arduino ()Source

Turn the display off. Note that turning the display off does not mean you are powering it down. It simply means that the characters will not be shown until you turn it back on using lcdDisplayOn. (Also, the contents will not be forgotten when you call this function.) Therefore, this function is useful for temporarily hiding the display contents.

Accessing internal symbols,

data LCDSymbol Source

An abstract symbol type for user created symbols

lcdInternalSymbol :: Word8 -> LCDSymbolSource

Access an internally stored symbol, one that is not available via its ASCII equivalent. See the Hitachi datasheet for possible values: http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf, Table 4 on page 17.

For instance, to access the symbol right-arrow:

  • Locate it in the above table: Right-arrow is at the second-to-last row, 7th character from left.
  • Check the upper/higher bits as specified in the table: For Right-arrow, upper bits are 0111 and the lower bits are 1110; which gives us the code 01111110, or 0x7E.
  • So, right-arrow can be accessed by symbol code lcdInternalSymbol 0x7E, which will give us a LCDSymbol value that can be passed to the lcdWriteSymbol function. The code would look like this: lcdWriteSymbol lcd (lcdInternalSymbol 0x7E).

lcdWriteSymbol :: LCD -> LCDSymbol -> Arduino ()Source

Display a user created symbol on the LCD. (See lcdCreateSymbol for details.)

lcdCreateSymbol :: LCD -> [String] -> Arduino LCDSymbolSource

Create a custom symbol for later display. Note that controllers have limited capability for such symbols, typically storing no more than 8. The behavior is undefined if you create more symbols than your LCD can handle.

The input is a simple description of the glyph, as a list of precisely 8 strings, each of which must have 5 characters. Any space character is interpreted as a empty pixel, any non-space is a full pixel, corresponding to the pixel in the 5x8 characters we have on the LCD. For instance, here's a happy-face glyph you can use:

   [ "     "
   , "@   @"
   , "     "
   , "     "
   , "@   @"
   , " @@@ "
   , "     "
   , "     "
   ]

Misc helpers

lcdFlashSource

Arguments

:: LCD 
-> Int

Flash count

-> Int

Delay amount (in milli-seconds)

-> Arduino () 

Flash contents of the LCD screen