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.
Fork of display by
main.cpp@0:c0be4e018a09, 2014-06-14 (annotated)
- Committer:
- morita
- Date:
- Sat Jun 14 02:27:06 2014 +0000
- Revision:
- 0:c0be4e018a09
- Child:
- 1:b64c81071d96
DL144128TF driving Test.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| morita | 0:c0be4e018a09 | 1 | /** |
| morita | 0:c0be4e018a09 | 2 | * @file main.c |
| morita | 0:c0be4e018a09 | 3 | * @brief ILI9163/DL144128TF 128x128 TFT LCD Test code |
| morita | 0:c0be4e018a09 | 4 | * |
| morita | 0:c0be4e018a09 | 5 | * This program is free software: you can redistribute it and/or modify |
| morita | 0:c0be4e018a09 | 6 | * it under the terms of the GNU General Public License as published by |
| morita | 0:c0be4e018a09 | 7 | * the Free Software Foundation, either version 3 of the License, or |
| morita | 0:c0be4e018a09 | 8 | * (at your option) any later version. |
| morita | 0:c0be4e018a09 | 9 | * |
| morita | 0:c0be4e018a09 | 10 | * This program is distributed in the hope that it will be useful, |
| morita | 0:c0be4e018a09 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| morita | 0:c0be4e018a09 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| morita | 0:c0be4e018a09 | 13 | * GNU General Public License for more details. |
| morita | 0:c0be4e018a09 | 14 | * |
| morita | 0:c0be4e018a09 | 15 | * You should have received a copy of the GNU General Public License |
| morita | 0:c0be4e018a09 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| morita | 0:c0be4e018a09 | 17 | * |
| morita | 0:c0be4e018a09 | 18 | * @author Jun Morita (iccraft) |
| morita | 0:c0be4e018a09 | 19 | * |
| morita | 0:c0be4e018a09 | 20 | * @copyright Copyright (C) 2012 Simon Inns |
| morita | 0:c0be4e018a09 | 21 | * @author Simon Inns <simon.inns@gmail.com> |
| morita | 0:c0be4e018a09 | 22 | */ |
| morita | 0:c0be4e018a09 | 23 | |
| morita | 0:c0be4e018a09 | 24 | #include "mbed.h" |
| morita | 0:c0be4e018a09 | 25 | #include "ili9163lcd.h" |
| morita | 0:c0be4e018a09 | 26 | |
| morita | 0:c0be4e018a09 | 27 | DigitalOut LED(LED1); |
| morita | 0:c0be4e018a09 | 28 | |
| morita | 0:c0be4e018a09 | 29 | int main() |
| morita | 0:c0be4e018a09 | 30 | { |
| morita | 0:c0be4e018a09 | 31 | uint8_t tm=10; |
| morita | 0:c0be4e018a09 | 32 | uint8_t R=0,G=0,B=0; |
| morita | 0:c0be4e018a09 | 33 | uint8_t RGB_state=0; |
| morita | 0:c0be4e018a09 | 34 | |
| morita | 0:c0be4e018a09 | 35 | lcdInitialise(LCD_ORIENTATION3); |
| morita | 0:c0be4e018a09 | 36 | |
| morita | 0:c0be4e018a09 | 37 | lcdClearDisplay(decodeRgbValue(0, 0, 0)); |
| morita | 0:c0be4e018a09 | 38 | |
| morita | 0:c0be4e018a09 | 39 | lcdLine(0, 0, 127, 127, decodeRgbValue(31, 31, 31)); |
| morita | 0:c0be4e018a09 | 40 | lcdLine(0, 127, 127, 0, decodeRgbValue(31, 31, 31)); |
| morita | 0:c0be4e018a09 | 41 | lcdCircle(64, 64, 32, decodeRgbValue(31, 0, 0)); |
| morita | 0:c0be4e018a09 | 42 | lcdCircle(64, 64, 40, decodeRgbValue(0, 31, 0)); |
| morita | 0:c0be4e018a09 | 43 | lcdCircle(64, 64, 48, decodeRgbValue(0, 0, 31)); |
| morita | 0:c0be4e018a09 | 44 | |
| morita | 0:c0be4e018a09 | 45 | lcdPutS("Hello World!", lcdTextX(4), lcdTextY(0), decodeRgbValue(0, 0, 0), decodeRgbValue(31, 31, 31)); |
| morita | 0:c0be4e018a09 | 46 | |
| morita | 0:c0be4e018a09 | 47 | lcdPutS("The quick brown fox jumped over the lazy dog 0123456789", lcdTextX(0), lcdTextY(2), decodeRgbValue(0, 31, 31), decodeRgbValue(0, 0, 0)); |
| morita | 0:c0be4e018a09 | 48 | |
| morita | 0:c0be4e018a09 | 49 | lcdFilledRectangle(0, 64, 127, 127, decodeRgbValue(0, 0, 0)); |
| morita | 0:c0be4e018a09 | 50 | lcdRectangle(0, 64, 127, 127, decodeRgbValue(31, 31, 31)); |
| morita | 0:c0be4e018a09 | 51 | |
| morita | 0:c0be4e018a09 | 52 | // Run the LCD test |
| morita | 0:c0be4e018a09 | 53 | uint8_t ballX = 64, ballY = 96; |
| morita | 0:c0be4e018a09 | 54 | int8_t ballSpeed = 1; |
| morita | 0:c0be4e018a09 | 55 | int8_t xDir = ballSpeed, yDir = ballSpeed; |
| morita | 0:c0be4e018a09 | 56 | |
| morita | 0:c0be4e018a09 | 57 | // Bouncy ball demo |
| morita | 0:c0be4e018a09 | 58 | while(1) |
| morita | 0:c0be4e018a09 | 59 | { |
| morita | 0:c0be4e018a09 | 60 | // Delete the ball |
| morita | 0:c0be4e018a09 | 61 | lcdFilledRectangle(ballX-2, ballY-1, ballX+2, ballY+1, decodeRgbValue(0, 0, 0)); |
| morita | 0:c0be4e018a09 | 62 | |
| morita | 0:c0be4e018a09 | 63 | // Delete the bat |
| morita | 0:c0be4e018a09 | 64 | lcdFilledRectangle(ballX-4, 121, ballX+4, 123, decodeRgbValue(0, 0, 0)); |
| morita | 0:c0be4e018a09 | 65 | |
| morita | 0:c0be4e018a09 | 66 | // Move the ball |
| morita | 0:c0be4e018a09 | 67 | ballX += xDir; |
| morita | 0:c0be4e018a09 | 68 | ballY += yDir; |
| morita | 0:c0be4e018a09 | 69 | |
| morita | 0:c0be4e018a09 | 70 | // Range check |
| morita | 0:c0be4e018a09 | 71 | if (ballX > 120) xDir = -ballSpeed; |
| morita | 0:c0be4e018a09 | 72 | if (ballX < 7) xDir = ballSpeed; |
| morita | 0:c0be4e018a09 | 73 | |
| morita | 0:c0be4e018a09 | 74 | if (ballY > 120) yDir = -ballSpeed; |
| morita | 0:c0be4e018a09 | 75 | if (ballY < 70) yDir = ballSpeed; |
| morita | 0:c0be4e018a09 | 76 | |
| morita | 0:c0be4e018a09 | 77 | // Plot the ball |
| morita | 0:c0be4e018a09 | 78 | lcdFilledRectangle(ballX-2, ballY-1, ballX+2, ballY+1, decodeRgbValue(31, 31, 31)); |
| morita | 0:c0be4e018a09 | 79 | |
| morita | 0:c0be4e018a09 | 80 | // Plot the bat |
| morita | 0:c0be4e018a09 | 81 | lcdFilledRectangle(ballX-4, 121, ballX+4, 123, decodeRgbValue(31, 0, 31)); |
| morita | 0:c0be4e018a09 | 82 | |
| morita | 0:c0be4e018a09 | 83 | // lcdPutS("Hello World!", lcdTextX(4), lcdTextY(0), decodeRgbValue(0, 0, 0), decodeRgbValue(31, 31, 31)); |
| morita | 0:c0be4e018a09 | 84 | lcdPutS("Hello World!", lcdTextX(4), lcdTextY(0), decodeRgbValue(0, 0, 0), decodeRgbValue(R, G, B)); |
| morita | 0:c0be4e018a09 | 85 | switch (RGB_state){ |
| morita | 0:c0be4e018a09 | 86 | case 0: |
| morita | 0:c0be4e018a09 | 87 | if(++R >= 31)RGB_state++; |
| morita | 0:c0be4e018a09 | 88 | break; |
| morita | 0:c0be4e018a09 | 89 | case 1: |
| morita | 0:c0be4e018a09 | 90 | if(--R == 0)RGB_state++; |
| morita | 0:c0be4e018a09 | 91 | break; |
| morita | 0:c0be4e018a09 | 92 | case 2: |
| morita | 0:c0be4e018a09 | 93 | if(++G >= 31)RGB_state++; |
| morita | 0:c0be4e018a09 | 94 | break; |
| morita | 0:c0be4e018a09 | 95 | case 3: |
| morita | 0:c0be4e018a09 | 96 | if(--G == 0)RGB_state++; |
| morita | 0:c0be4e018a09 | 97 | break; |
| morita | 0:c0be4e018a09 | 98 | case 4: |
| morita | 0:c0be4e018a09 | 99 | if(++B >= 31)RGB_state++; |
| morita | 0:c0be4e018a09 | 100 | break; |
| morita | 0:c0be4e018a09 | 101 | case 5: |
| morita | 0:c0be4e018a09 | 102 | if(--B == 0)RGB_state++; |
| morita | 0:c0be4e018a09 | 103 | break; |
| morita | 0:c0be4e018a09 | 104 | case 6: |
| morita | 0:c0be4e018a09 | 105 | if(++R >= 31)RGB_state++; |
| morita | 0:c0be4e018a09 | 106 | B = R; |
| morita | 0:c0be4e018a09 | 107 | break; |
| morita | 0:c0be4e018a09 | 108 | case 7: |
| morita | 0:c0be4e018a09 | 109 | if(-- R== 0)RGB_state++; |
| morita | 0:c0be4e018a09 | 110 | B = R; |
| morita | 0:c0be4e018a09 | 111 | break; |
| morita | 0:c0be4e018a09 | 112 | case 8: |
| morita | 0:c0be4e018a09 | 113 | if(++R >= 31)RGB_state++; |
| morita | 0:c0be4e018a09 | 114 | G = R; |
| morita | 0:c0be4e018a09 | 115 | break; |
| morita | 0:c0be4e018a09 | 116 | case 9: |
| morita | 0:c0be4e018a09 | 117 | if(-- R== 0)RGB_state++; |
| morita | 0:c0be4e018a09 | 118 | G = R; |
| morita | 0:c0be4e018a09 | 119 | break; |
| morita | 0:c0be4e018a09 | 120 | case 10: |
| morita | 0:c0be4e018a09 | 121 | if(++G >= 31)RGB_state++; |
| morita | 0:c0be4e018a09 | 122 | B = G; |
| morita | 0:c0be4e018a09 | 123 | break; |
| morita | 0:c0be4e018a09 | 124 | case 11: |
| morita | 0:c0be4e018a09 | 125 | if(-- G== 0)RGB_state++; |
| morita | 0:c0be4e018a09 | 126 | B = G; |
| morita | 0:c0be4e018a09 | 127 | break; |
| morita | 0:c0be4e018a09 | 128 | case 12: |
| morita | 0:c0be4e018a09 | 129 | if(++R >= 31)RGB_state++; |
| morita | 0:c0be4e018a09 | 130 | B = G = R; |
| morita | 0:c0be4e018a09 | 131 | break; |
| morita | 0:c0be4e018a09 | 132 | case 13: |
| morita | 0:c0be4e018a09 | 133 | if(--R == 0)RGB_state = 0; |
| morita | 0:c0be4e018a09 | 134 | B = G = R; |
| morita | 0:c0be4e018a09 | 135 | break; |
| morita | 0:c0be4e018a09 | 136 | } |
| morita | 0:c0be4e018a09 | 137 | wait_ms(10); |
| morita | 0:c0be4e018a09 | 138 | if(--tm==0){ |
| morita | 0:c0be4e018a09 | 139 | tm=10; |
| morita | 0:c0be4e018a09 | 140 | LED = LED ^ 1; |
| morita | 0:c0be4e018a09 | 141 | } |
| morita | 0:c0be4e018a09 | 142 | } |
| morita | 0:c0be4e018a09 | 143 | } |
