Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ulcd_demo/main.cpp@0:6a73d3dc037e, 2014-07-28 (annotated)
- Committer:
- ShawnHymel
- Date:
- Mon Jul 28 20:29:28 2014 +0000
- Revision:
- 0:6a73d3dc037e
Added main.cpp files from each of the demo programs. Libraries are not included.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ShawnHymel | 0:6a73d3dc037e | 1 | // Demo for the uLCD-144-G2 based on the work by Jim Hamblen |
| ShawnHymel | 0:6a73d3dc037e | 2 | |
| ShawnHymel | 0:6a73d3dc037e | 3 | #include "mbed.h" |
| ShawnHymel | 0:6a73d3dc037e | 4 | #include "uLCD_4DGL.h" |
| ShawnHymel | 0:6a73d3dc037e | 5 | |
| ShawnHymel | 0:6a73d3dc037e | 6 | // TX, RX, and RES pins |
| ShawnHymel | 0:6a73d3dc037e | 7 | uLCD_4DGL uLCD(p9,p10,p11); |
| ShawnHymel | 0:6a73d3dc037e | 8 | |
| ShawnHymel | 0:6a73d3dc037e | 9 | int main() { |
| ShawnHymel | 0:6a73d3dc037e | 10 | |
| ShawnHymel | 0:6a73d3dc037e | 11 | int x; |
| ShawnHymel | 0:6a73d3dc037e | 12 | int y; |
| ShawnHymel | 0:6a73d3dc037e | 13 | int radius; |
| ShawnHymel | 0:6a73d3dc037e | 14 | int vx; |
| ShawnHymel | 0:6a73d3dc037e | 15 | |
| ShawnHymel | 0:6a73d3dc037e | 16 | // Set our UART baudrate to something reasonable |
| ShawnHymel | 0:6a73d3dc037e | 17 | uLCD.baudrate(115200); |
| ShawnHymel | 0:6a73d3dc037e | 18 | |
| ShawnHymel | 0:6a73d3dc037e | 19 | // Change background color (must be called before cls) |
| ShawnHymel | 0:6a73d3dc037e | 20 | uLCD.background_color(WHITE); |
| ShawnHymel | 0:6a73d3dc037e | 21 | |
| ShawnHymel | 0:6a73d3dc037e | 22 | // Clear screen with background color |
| ShawnHymel | 0:6a73d3dc037e | 23 | uLCD.cls(); |
| ShawnHymel | 0:6a73d3dc037e | 24 | |
| ShawnHymel | 0:6a73d3dc037e | 25 | // Change background color of text |
| ShawnHymel | 0:6a73d3dc037e | 26 | uLCD.textbackground_color(WHITE); |
| ShawnHymel | 0:6a73d3dc037e | 27 | |
| ShawnHymel | 0:6a73d3dc037e | 28 | // Make some colorful text |
| ShawnHymel | 0:6a73d3dc037e | 29 | uLCD.locate(4, 1); // Move cursor |
| ShawnHymel | 0:6a73d3dc037e | 30 | uLCD.color(BLUE); |
| ShawnHymel | 0:6a73d3dc037e | 31 | uLCD.printf("This is a\n"); |
| ShawnHymel | 0:6a73d3dc037e | 32 | uLCD.locate(5, 3); // Move cursor |
| ShawnHymel | 0:6a73d3dc037e | 33 | uLCD.text_width(2); // 2x normal size |
| ShawnHymel | 0:6a73d3dc037e | 34 | uLCD.text_height(2); // 2x normal size |
| ShawnHymel | 0:6a73d3dc037e | 35 | uLCD.color(RED); // Change text color |
| ShawnHymel | 0:6a73d3dc037e | 36 | uLCD.printf("TEST"); |
| ShawnHymel | 0:6a73d3dc037e | 37 | uLCD.text_width(1); // Normal size |
| ShawnHymel | 0:6a73d3dc037e | 38 | uLCD.text_height(1); // Normal size |
| ShawnHymel | 0:6a73d3dc037e | 39 | uLCD.locate(3, 6); // Move cursor |
| ShawnHymel | 0:6a73d3dc037e | 40 | uLCD.color(BLACK); // Change text color |
| ShawnHymel | 0:6a73d3dc037e | 41 | uLCD.printf("of my new LCD"); |
| ShawnHymel | 0:6a73d3dc037e | 42 | |
| ShawnHymel | 0:6a73d3dc037e | 43 | // Initial parameters for the circle |
| ShawnHymel | 0:6a73d3dc037e | 44 | x = 50; |
| ShawnHymel | 0:6a73d3dc037e | 45 | y = 100; |
| ShawnHymel | 0:6a73d3dc037e | 46 | radius = 4; |
| ShawnHymel | 0:6a73d3dc037e | 47 | vx = 1; |
| ShawnHymel | 0:6a73d3dc037e | 48 | |
| ShawnHymel | 0:6a73d3dc037e | 49 | // Make a ball bounce back and forth |
| ShawnHymel | 0:6a73d3dc037e | 50 | while (1) { |
| ShawnHymel | 0:6a73d3dc037e | 51 | |
| ShawnHymel | 0:6a73d3dc037e | 52 | // Draw a dark green |
| ShawnHymel | 0:6a73d3dc037e | 53 | uLCD.filled_circle(x, y, radius, 0x008000); |
| ShawnHymel | 0:6a73d3dc037e | 54 | |
| ShawnHymel | 0:6a73d3dc037e | 55 | // Bounce off the edges |
| ShawnHymel | 0:6a73d3dc037e | 56 | if ((x <= radius + 1) || (x >= 126 - radius)) { |
| ShawnHymel | 0:6a73d3dc037e | 57 | vx = -1 * vx; |
| ShawnHymel | 0:6a73d3dc037e | 58 | } |
| ShawnHymel | 0:6a73d3dc037e | 59 | |
| ShawnHymel | 0:6a73d3dc037e | 60 | // Wait before erasing old circle |
| ShawnHymel | 0:6a73d3dc037e | 61 | wait(0.02); // In seconds |
| ShawnHymel | 0:6a73d3dc037e | 62 | |
| ShawnHymel | 0:6a73d3dc037e | 63 | // Erase old circle |
| ShawnHymel | 0:6a73d3dc037e | 64 | uLCD.filled_circle(x, y, radius, WHITE); |
| ShawnHymel | 0:6a73d3dc037e | 65 | |
| ShawnHymel | 0:6a73d3dc037e | 66 | // Move circle |
| ShawnHymel | 0:6a73d3dc037e | 67 | x = x + vx; |
| ShawnHymel | 0:6a73d3dc037e | 68 | } |
| ShawnHymel | 0:6a73d3dc037e | 69 | } |