This sketch demonstrates how to use leftToRight() and rightToLeft() to move the cursor.
Dependencies: Hotboards_SpiLcd mbed
main.cpp@0:578fd358c3d3, 2016-02-02 (annotated)
- Committer:
- Hotboards
- Date:
- Tue Feb 02 22:50:35 2016 +0000
- Revision:
- 0:578fd358c3d3
First Release: Hotboards_SpiLcd_TextDirection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hotboards | 0:578fd358c3d3 | 1 | /* |
Hotboards | 0:578fd358c3d3 | 2 | Hotboards_SpiLcd - TextDirection |
Hotboards | 0:578fd358c3d3 | 3 | Demonstrates the use a 16x2 LCD display. The Hotboards_SpiLcd |
Hotboards | 0:578fd358c3d3 | 4 | library works with all LCD displays that are compatible with the |
Hotboards | 0:578fd358c3d3 | 5 | ST7032 driver presented on Spi Lcd board (http://www.hotboards.org). |
Hotboards | 0:578fd358c3d3 | 6 | This sketch demonstrates how to use leftToRight() and rightToLeft() |
Hotboards | 0:578fd358c3d3 | 7 | to move the cursor. |
Hotboards | 0:578fd358c3d3 | 8 | The circuit: |
Hotboards | 0:578fd358c3d3 | 9 | * BKL --> GND |
Hotboards | 0:578fd358c3d3 | 10 | * VDD --> 3.3v |
Hotboards | 0:578fd358c3d3 | 11 | * GND --> GND |
Hotboards | 0:578fd358c3d3 | 12 | * SCK --> PA_5 |
Hotboards | 0:578fd358c3d3 | 13 | * SI --> PA_6 |
Hotboards | 0:578fd358c3d3 | 14 | * CS --> PB_15 |
Hotboards | 0:578fd358c3d3 | 15 | * RS --> PB_14 |
Hotboards | 0:578fd358c3d3 | 16 | * RST --> PB_13 |
Hotboards | 0:578fd358c3d3 | 17 | Library and example ported by Diego from Hotboards and originally created |
Hotboards | 0:578fd358c3d3 | 18 | by David A. Mellis |
Hotboards | 0:578fd358c3d3 | 19 | library modified 5 Jul 2009 |
Hotboards | 0:578fd358c3d3 | 20 | by Limor Fried (http://www.ladyada.net) |
Hotboards | 0:578fd358c3d3 | 21 | example added 9 Jul 2009 |
Hotboards | 0:578fd358c3d3 | 22 | by Tom Igoe |
Hotboards | 0:578fd358c3d3 | 23 | modified 22 Nov 2010 |
Hotboards | 0:578fd358c3d3 | 24 | by Tom Igoe |
Hotboards | 0:578fd358c3d3 | 25 | */ |
Hotboards | 0:578fd358c3d3 | 26 | #include "mbed.h" |
Hotboards | 0:578fd358c3d3 | 27 | #include "Hotboards_SpiLcd.h" |
Hotboards | 0:578fd358c3d3 | 28 | |
Hotboards | 0:578fd358c3d3 | 29 | /* initialize an instance of SPI bus,setting the SPI pins*/ |
Hotboards | 0:578fd358c3d3 | 30 | SPI device(PA_7,PA_6,PA_5); /* SO, SI, SCK*/ |
Hotboards | 0:578fd358c3d3 | 31 | /* initialize the library with the numbers of the interface pins*/ |
Hotboards | 0:578fd358c3d3 | 32 | Hotboards_SpiLcd display( device, PB_15, PB_14, PB_13 ); /* SPI, CS, RS, RST */ |
Hotboards | 0:578fd358c3d3 | 33 | |
Hotboards | 0:578fd358c3d3 | 34 | int thisChar = 'a'; |
Hotboards | 0:578fd358c3d3 | 35 | |
Hotboards | 0:578fd358c3d3 | 36 | int main() |
Hotboards | 0:578fd358c3d3 | 37 | { |
Hotboards | 0:578fd358c3d3 | 38 | /* set the spi frequency to 5MHz*/ |
Hotboards | 0:578fd358c3d3 | 39 | device.frequency(5000000); |
Hotboards | 0:578fd358c3d3 | 40 | /* initialize internal lcd controller:*/ |
Hotboards | 0:578fd358c3d3 | 41 | display.init(); |
Hotboards | 0:578fd358c3d3 | 42 | // turn on the cursor: |
Hotboards | 0:578fd358c3d3 | 43 | display.cursor(); |
Hotboards | 0:578fd358c3d3 | 44 | |
Hotboards | 0:578fd358c3d3 | 45 | while(1) |
Hotboards | 0:578fd358c3d3 | 46 | { |
Hotboards | 0:578fd358c3d3 | 47 | // reverse directions at 'm': |
Hotboards | 0:578fd358c3d3 | 48 | if (thisChar == 'm') |
Hotboards | 0:578fd358c3d3 | 49 | { |
Hotboards | 0:578fd358c3d3 | 50 | // go right for the next letter |
Hotboards | 0:578fd358c3d3 | 51 | display.rightToLeft(); |
Hotboards | 0:578fd358c3d3 | 52 | } |
Hotboards | 0:578fd358c3d3 | 53 | // reverse again at 's': |
Hotboards | 0:578fd358c3d3 | 54 | if (thisChar == 's') |
Hotboards | 0:578fd358c3d3 | 55 | { |
Hotboards | 0:578fd358c3d3 | 56 | // go left for the next letter |
Hotboards | 0:578fd358c3d3 | 57 | display.leftToRight(); |
Hotboards | 0:578fd358c3d3 | 58 | } |
Hotboards | 0:578fd358c3d3 | 59 | // reset at 'z': |
Hotboards | 0:578fd358c3d3 | 60 | if (thisChar > 'z') |
Hotboards | 0:578fd358c3d3 | 61 | { |
Hotboards | 0:578fd358c3d3 | 62 | // go to (0,0): |
Hotboards | 0:578fd358c3d3 | 63 | display.home(); |
Hotboards | 0:578fd358c3d3 | 64 | // start again at 0 |
Hotboards | 0:578fd358c3d3 | 65 | thisChar = 'a'; |
Hotboards | 0:578fd358c3d3 | 66 | } |
Hotboards | 0:578fd358c3d3 | 67 | // print the character |
Hotboards | 0:578fd358c3d3 | 68 | display.printf("%c",thisChar); |
Hotboards | 0:578fd358c3d3 | 69 | // wait a second: |
Hotboards | 0:578fd358c3d3 | 70 | wait(1); |
Hotboards | 0:578fd358c3d3 | 71 | // increment the letter: |
Hotboards | 0:578fd358c3d3 | 72 | thisChar++; |
Hotboards | 0:578fd358c3d3 | 73 | } |
Hotboards | 0:578fd358c3d3 | 74 | } |