License | BSD3 |
---|---|
Stability | experimental |
Portability | GHC-only |
Safe Haskell | None |
Language | Haskell2010 |
The LCD module has been copied from the hArduino package. This is the System.Hardware.Arduino.Parts.LCD ((c) Levent Erkok) with some minor adaption for STM32.
- data LCD
- data LCDController = Hitachi44780 {}
- lcdRegister :: LCDController -> MI LCD
- lcdClear :: LCD -> MI ()
- lcdWrite :: LCD -> String -> MI ()
- lcdHome :: LCD -> MI ()
- lcdSetCursor :: LCD -> (Int, Int) -> MI ()
- lcdAutoScrollOn :: LCD -> MI ()
- lcdAutoScrollOff :: LCD -> MI ()
- lcdScrollDisplayLeft :: LCD -> MI ()
- lcdScrollDisplayRight :: LCD -> MI ()
- lcdLeftToRight :: LCD -> MI ()
- lcdRightToLeft :: LCD -> MI ()
- lcdBlinkOn :: LCD -> MI ()
- lcdBlinkOff :: LCD -> MI ()
- lcdCursorOn :: LCD -> MI ()
- lcdCursorOff :: LCD -> MI ()
- lcdDisplayOn :: LCD -> MI ()
- lcdDisplayOff :: LCD -> MI ()
- data LCDSymbol
- lcdInternalSymbol :: Word8 -> LCDSymbol
- lcdWriteSymbol :: LCD -> LCDSymbol -> MI ()
- lcdCreateSymbol :: LCD -> [String] -> MI LCDSymbol
- lcdFlash :: LCD -> Int -> Int -> MI ()
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.
Hitachi44780 | |
|
lcdRegister :: LCDController -> MI LCD Source #
Register an LCD controller. When registration is complete, the LCD will be initialized so that:
- Set display ON (Use
lcdDisplayOn
/lcdDisplayOff
to change.) - Set cursor OFF (Use
lcdCursorOn
/lcdCursorOff
to change.) - Set blink OFF (Use
lcdBlinkOn
/lcdBlinkOff
to change.) - Clear display (Use
lcdClear
to clear,lcdWrite
to display text.) - Set entry mode left to write (Use
lcdLeftToRight
/lcdRightToLeft
to control.) - Set autoscrolling OFF (Use
lcdAutoScrollOff
/lcdAutoScrollOn
to control.) - Put the cursor into home position (Use
lcdSetCursor
orlcdHome
to move around.)
Writing text on the LCD
Moving the cursor
lcdSetCursor :: LCD -> (Int, Int) -> MI () 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 -> MI () 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 -> MI () 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 -> MI () 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 -> MI () Source #
Scroll the display to the right by 1 character
Display properties
lcdLeftToRight :: LCD -> MI () Source #
Set writing direction: Left to Right
lcdRightToLeft :: LCD -> MI () Source #
Set writing direction: Right to Left
lcdBlinkOn :: LCD -> MI () Source #
Blink the cursor
lcdBlinkOff :: LCD -> MI () Source #
Do not blink the cursor
lcdCursorOn :: LCD -> MI () Source #
Show the cursor
lcdCursorOff :: LCD -> MI () Source #
Hide the cursor. Note that a blinking cursor cannot be hidden, you must first turn off blinking.
lcdDisplayOn :: LCD -> MI () Source #
Turn the display on
lcdDisplayOff :: LCD -> MI () 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,
lcdInternalSymbol :: Word8 -> LCDSymbol Source #
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 are1110
; which gives us the code01111110
, or0x7E
. - So, right-arrow can be accessed by symbol code
lcdInternalSymbol
0x7E
, which will give us aLCDSymbol
value that can be passed to thelcdWriteSymbol
function. The code would look like this:lcdWriteSymbol lcd (lcdInternalSymbol 0x7E)
.
lcdWriteSymbol :: LCD -> LCDSymbol -> MI () Source #
Display a user created symbol on the LCD. (See lcdCreateSymbol
for details.)
lcdCreateSymbol :: LCD -> [String] -> MI LCDSymbol Source #
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:
[ " " , "@ @" , " " , " " , "@ @" , " @@@ " , " " , " " ]