This sketch prints "Hello World!" to the LCD and uses the scrollDisplayLeft() and scrollDisplayRight() methods to scroll the text.
Dependencies: Hotboards_SpiLcd mbed
main.cpp@0:bd5a3c76e81f, 2016-02-02 (annotated)
- Committer:
- Hotboards
- Date:
- Tue Feb 02 22:17:34 2016 +0000
- Revision:
- 0:bd5a3c76e81f
First release: Hotboards_SpiLcd_Scroll
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hotboards | 0:bd5a3c76e81f | 1 | /* |
Hotboards | 0:bd5a3c76e81f | 2 | LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() |
Hotboards | 0:bd5a3c76e81f | 3 | Demonstrates the use a 16x2 LCD display. The Hotboards_SpiLcd |
Hotboards | 0:bd5a3c76e81f | 4 | library works with all LCD displays that are compatible with the |
Hotboards | 0:bd5a3c76e81f | 5 | ST7032 driver presented on Spi Lcd board (http://www.hotboards.org). |
Hotboards | 0:bd5a3c76e81f | 6 | This sketch prints "Hello World!" to the LCD and uses the |
Hotboards | 0:bd5a3c76e81f | 7 | scrollDisplayLeft() and scrollDisplayRight() methods to scroll |
Hotboards | 0:bd5a3c76e81f | 8 | the text. |
Hotboards | 0:bd5a3c76e81f | 9 | The circuit: |
Hotboards | 0:bd5a3c76e81f | 10 | * BKL --> GND |
Hotboards | 0:bd5a3c76e81f | 11 | * VDD --> 3.3v |
Hotboards | 0:bd5a3c76e81f | 12 | * GND --> GND |
Hotboards | 0:bd5a3c76e81f | 13 | * SCK --> PA_5 |
Hotboards | 0:bd5a3c76e81f | 14 | * SI --> PA_6 |
Hotboards | 0:bd5a3c76e81f | 15 | * CS --> PB_15 |
Hotboards | 0:bd5a3c76e81f | 16 | * RS --> PB_14 |
Hotboards | 0:bd5a3c76e81f | 17 | * RST --> PB_13 |
Hotboards | 0:bd5a3c76e81f | 18 | Library and example ported by Diego from Hotboards and originally created |
Hotboards | 0:bd5a3c76e81f | 19 | by David A. Mellis |
Hotboards | 0:bd5a3c76e81f | 20 | library modified 5 Jul 2009 |
Hotboards | 0:bd5a3c76e81f | 21 | by Limor Fried (http://www.ladyada.net) |
Hotboards | 0:bd5a3c76e81f | 22 | example added 9 Jul 2009 |
Hotboards | 0:bd5a3c76e81f | 23 | by Tom Igoe |
Hotboards | 0:bd5a3c76e81f | 24 | modified 22 Nov 2010 |
Hotboards | 0:bd5a3c76e81f | 25 | by Tom Igoe |
Hotboards | 0:bd5a3c76e81f | 26 | */ |
Hotboards | 0:bd5a3c76e81f | 27 | |
Hotboards | 0:bd5a3c76e81f | 28 | #include "mbed.h" |
Hotboards | 0:bd5a3c76e81f | 29 | #include "Hotboards_SpiLcd.h" |
Hotboards | 0:bd5a3c76e81f | 30 | |
Hotboards | 0:bd5a3c76e81f | 31 | /* initialize an instance of SPI bus,setting the SPI pins*/ |
Hotboards | 0:bd5a3c76e81f | 32 | SPI device(PA_7,PA_6,PA_5); /* SO, SI, SCK*/ |
Hotboards | 0:bd5a3c76e81f | 33 | /* initialize the library with the numbers of the interface pins*/ |
Hotboards | 0:bd5a3c76e81f | 34 | Hotboards_SpiLcd display( device, PB_15, PB_14, PB_13 ); /* SPI, CS, RS, RST */ |
Hotboards | 0:bd5a3c76e81f | 35 | |
Hotboards | 0:bd5a3c76e81f | 36 | |
Hotboards | 0:bd5a3c76e81f | 37 | int main() |
Hotboards | 0:bd5a3c76e81f | 38 | { |
Hotboards | 0:bd5a3c76e81f | 39 | /* set the spi frequency to 5MHz*/ |
Hotboards | 0:bd5a3c76e81f | 40 | device.frequency(5000000); |
Hotboards | 0:bd5a3c76e81f | 41 | /* initialize internal lcd controller:*/ |
Hotboards | 0:bd5a3c76e81f | 42 | display.init(); |
Hotboards | 0:bd5a3c76e81f | 43 | // Print a message to the LCD. |
Hotboards | 0:bd5a3c76e81f | 44 | display.printf("hello, world!"); |
Hotboards | 0:bd5a3c76e81f | 45 | wait(1); |
Hotboards | 0:bd5a3c76e81f | 46 | |
Hotboards | 0:bd5a3c76e81f | 47 | while(1) |
Hotboards | 0:bd5a3c76e81f | 48 | { |
Hotboards | 0:bd5a3c76e81f | 49 | // scroll 13 positions (string length) to the left |
Hotboards | 0:bd5a3c76e81f | 50 | // to move it offscreen left: |
Hotboards | 0:bd5a3c76e81f | 51 | for (int positionCounter = 0; positionCounter < 13; positionCounter++) |
Hotboards | 0:bd5a3c76e81f | 52 | { |
Hotboards | 0:bd5a3c76e81f | 53 | // scroll one position left: |
Hotboards | 0:bd5a3c76e81f | 54 | display.scrollDisplayLeft(); |
Hotboards | 0:bd5a3c76e81f | 55 | // wait a bit: |
Hotboards | 0:bd5a3c76e81f | 56 | wait(0.2); |
Hotboards | 0:bd5a3c76e81f | 57 | } |
Hotboards | 0:bd5a3c76e81f | 58 | |
Hotboards | 0:bd5a3c76e81f | 59 | // scroll 29 positions (string length + display length) to the right |
Hotboards | 0:bd5a3c76e81f | 60 | // to move it offscreen right: |
Hotboards | 0:bd5a3c76e81f | 61 | for (int positionCounter = 0; positionCounter < 29; positionCounter++) |
Hotboards | 0:bd5a3c76e81f | 62 | { |
Hotboards | 0:bd5a3c76e81f | 63 | // scroll one position right: |
Hotboards | 0:bd5a3c76e81f | 64 | display.scrollDisplayRight(); |
Hotboards | 0:bd5a3c76e81f | 65 | // wait a bit: |
Hotboards | 0:bd5a3c76e81f | 66 | wait(0.2); |
Hotboards | 0:bd5a3c76e81f | 67 | } |
Hotboards | 0:bd5a3c76e81f | 68 | |
Hotboards | 0:bd5a3c76e81f | 69 | // scroll 16 positions (display length + string length) to the left |
Hotboards | 0:bd5a3c76e81f | 70 | // to move it back to center: |
Hotboards | 0:bd5a3c76e81f | 71 | for (int positionCounter = 0; positionCounter < 16; positionCounter++) |
Hotboards | 0:bd5a3c76e81f | 72 | { |
Hotboards | 0:bd5a3c76e81f | 73 | // scroll one position left: |
Hotboards | 0:bd5a3c76e81f | 74 | display.scrollDisplayLeft(); |
Hotboards | 0:bd5a3c76e81f | 75 | // wait a bit: |
Hotboards | 0:bd5a3c76e81f | 76 | wait(0.2); |
Hotboards | 0:bd5a3c76e81f | 77 | } |
Hotboards | 0:bd5a3c76e81f | 78 | |
Hotboards | 0:bd5a3c76e81f | 79 | // delay at the end of the full loop: |
Hotboards | 0:bd5a3c76e81f | 80 | wait(1); |
Hotboards | 0:bd5a3c76e81f | 81 | } |
Hotboards | 0:bd5a3c76e81f | 82 | } |