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.
main.cpp@2:4d5b94a92f19, 2021-01-01 (annotated)
- Committer:
- gitakichi
- Date:
- Fri Jan 01 13:57:57 2021 +0000
- Revision:
- 2:4d5b94a92f19
- Parent:
- 0:c0be4e018a09
- Child:
- 3:9caa79f40909
delete redundant code
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 |
gitakichi | 2:4d5b94a92f19 | 3 | * @brief ATM0177B3A(ILI9163 128x160) 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 | * |
gitakichi | 2:4d5b94a92f19 | 18 | * @author Gitakichi |
morita | 0:c0be4e018a09 | 19 | * @author Jun Morita (iccraft) |
morita | 0:c0be4e018a09 | 20 | * |
morita | 0:c0be4e018a09 | 21 | * @copyright Copyright (C) 2012 Simon Inns |
morita | 0:c0be4e018a09 | 22 | * @author Simon Inns <simon.inns@gmail.com> |
morita | 0:c0be4e018a09 | 23 | */ |
morita | 0:c0be4e018a09 | 24 | |
morita | 0:c0be4e018a09 | 25 | #include "mbed.h" |
morita | 0:c0be4e018a09 | 26 | #include "ili9163lcd.h" |
morita | 0:c0be4e018a09 | 27 | |
morita | 0:c0be4e018a09 | 28 | DigitalOut LED(LED1); |
morita | 0:c0be4e018a09 | 29 | |
morita | 0:c0be4e018a09 | 30 | int main() |
morita | 0:c0be4e018a09 | 31 | { |
morita | 0:c0be4e018a09 | 32 | uint8_t tm=10; |
morita | 0:c0be4e018a09 | 33 | uint8_t R=0,G=0,B=0; |
morita | 0:c0be4e018a09 | 34 | uint8_t RGB_state=0; |
morita | 0:c0be4e018a09 | 35 | |
gitakichi | 2:4d5b94a92f19 | 36 | //lcdInitialise(LCD_ORIENTATION3); |
gitakichi | 2:4d5b94a92f19 | 37 | lcdInitialise(ROT_BOTTOM); |
morita | 0:c0be4e018a09 | 38 | |
morita | 0:c0be4e018a09 | 39 | lcdClearDisplay(decodeRgbValue(0, 0, 0)); |
morita | 0:c0be4e018a09 | 40 | |
morita | 0:c0be4e018a09 | 41 | lcdLine(0, 0, 127, 127, decodeRgbValue(31, 31, 31)); |
morita | 0:c0be4e018a09 | 42 | lcdLine(0, 127, 127, 0, decodeRgbValue(31, 31, 31)); |
morita | 0:c0be4e018a09 | 43 | lcdCircle(64, 64, 32, decodeRgbValue(31, 0, 0)); |
morita | 0:c0be4e018a09 | 44 | lcdCircle(64, 64, 40, decodeRgbValue(0, 31, 0)); |
morita | 0:c0be4e018a09 | 45 | lcdCircle(64, 64, 48, decodeRgbValue(0, 0, 31)); |
morita | 0:c0be4e018a09 | 46 | |
morita | 0:c0be4e018a09 | 47 | lcdPutS("Hello World!", lcdTextX(4), lcdTextY(0), decodeRgbValue(0, 0, 0), decodeRgbValue(31, 31, 31)); |
morita | 0:c0be4e018a09 | 48 | |
morita | 0:c0be4e018a09 | 49 | 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 | 50 | |
morita | 0:c0be4e018a09 | 51 | lcdFilledRectangle(0, 64, 127, 127, decodeRgbValue(0, 0, 0)); |
morita | 0:c0be4e018a09 | 52 | lcdRectangle(0, 64, 127, 127, decodeRgbValue(31, 31, 31)); |
gitakichi | 2:4d5b94a92f19 | 53 | |
morita | 0:c0be4e018a09 | 54 | // Run the LCD test |
morita | 0:c0be4e018a09 | 55 | uint8_t ballX = 64, ballY = 96; |
morita | 0:c0be4e018a09 | 56 | int8_t ballSpeed = 1; |
morita | 0:c0be4e018a09 | 57 | int8_t xDir = ballSpeed, yDir = ballSpeed; |
morita | 0:c0be4e018a09 | 58 | |
gitakichi | 2:4d5b94a92f19 | 59 | |
morita | 0:c0be4e018a09 | 60 | // Bouncy ball demo |
morita | 0:c0be4e018a09 | 61 | while(1) |
morita | 0:c0be4e018a09 | 62 | { |
morita | 0:c0be4e018a09 | 63 | // Delete the ball |
morita | 0:c0be4e018a09 | 64 | lcdFilledRectangle(ballX-2, ballY-1, ballX+2, ballY+1, decodeRgbValue(0, 0, 0)); |
morita | 0:c0be4e018a09 | 65 | |
morita | 0:c0be4e018a09 | 66 | // Delete the bat |
morita | 0:c0be4e018a09 | 67 | lcdFilledRectangle(ballX-4, 121, ballX+4, 123, decodeRgbValue(0, 0, 0)); |
morita | 0:c0be4e018a09 | 68 | |
morita | 0:c0be4e018a09 | 69 | // Move the ball |
morita | 0:c0be4e018a09 | 70 | ballX += xDir; |
morita | 0:c0be4e018a09 | 71 | ballY += yDir; |
morita | 0:c0be4e018a09 | 72 | |
morita | 0:c0be4e018a09 | 73 | // Range check |
morita | 0:c0be4e018a09 | 74 | if (ballX > 120) xDir = -ballSpeed; |
morita | 0:c0be4e018a09 | 75 | if (ballX < 7) xDir = ballSpeed; |
morita | 0:c0be4e018a09 | 76 | |
morita | 0:c0be4e018a09 | 77 | if (ballY > 120) yDir = -ballSpeed; |
morita | 0:c0be4e018a09 | 78 | if (ballY < 70) yDir = ballSpeed; |
morita | 0:c0be4e018a09 | 79 | |
morita | 0:c0be4e018a09 | 80 | // Plot the ball |
morita | 0:c0be4e018a09 | 81 | lcdFilledRectangle(ballX-2, ballY-1, ballX+2, ballY+1, decodeRgbValue(31, 31, 31)); |
morita | 0:c0be4e018a09 | 82 | |
morita | 0:c0be4e018a09 | 83 | // Plot the bat |
morita | 0:c0be4e018a09 | 84 | lcdFilledRectangle(ballX-4, 121, ballX+4, 123, decodeRgbValue(31, 0, 31)); |
morita | 0:c0be4e018a09 | 85 | |
morita | 0:c0be4e018a09 | 86 | // lcdPutS("Hello World!", lcdTextX(4), lcdTextY(0), decodeRgbValue(0, 0, 0), decodeRgbValue(31, 31, 31)); |
morita | 0:c0be4e018a09 | 87 | lcdPutS("Hello World!", lcdTextX(4), lcdTextY(0), decodeRgbValue(0, 0, 0), decodeRgbValue(R, G, B)); |
morita | 0:c0be4e018a09 | 88 | switch (RGB_state){ |
morita | 0:c0be4e018a09 | 89 | case 0: |
morita | 0:c0be4e018a09 | 90 | if(++R >= 31)RGB_state++; |
morita | 0:c0be4e018a09 | 91 | break; |
morita | 0:c0be4e018a09 | 92 | case 1: |
morita | 0:c0be4e018a09 | 93 | if(--R == 0)RGB_state++; |
morita | 0:c0be4e018a09 | 94 | break; |
morita | 0:c0be4e018a09 | 95 | case 2: |
morita | 0:c0be4e018a09 | 96 | if(++G >= 31)RGB_state++; |
morita | 0:c0be4e018a09 | 97 | break; |
morita | 0:c0be4e018a09 | 98 | case 3: |
morita | 0:c0be4e018a09 | 99 | if(--G == 0)RGB_state++; |
morita | 0:c0be4e018a09 | 100 | break; |
morita | 0:c0be4e018a09 | 101 | case 4: |
morita | 0:c0be4e018a09 | 102 | if(++B >= 31)RGB_state++; |
morita | 0:c0be4e018a09 | 103 | break; |
morita | 0:c0be4e018a09 | 104 | case 5: |
morita | 0:c0be4e018a09 | 105 | if(--B == 0)RGB_state++; |
morita | 0:c0be4e018a09 | 106 | break; |
morita | 0:c0be4e018a09 | 107 | case 6: |
morita | 0:c0be4e018a09 | 108 | if(++R >= 31)RGB_state++; |
morita | 0:c0be4e018a09 | 109 | B = R; |
morita | 0:c0be4e018a09 | 110 | break; |
morita | 0:c0be4e018a09 | 111 | case 7: |
morita | 0:c0be4e018a09 | 112 | if(-- R== 0)RGB_state++; |
morita | 0:c0be4e018a09 | 113 | B = R; |
morita | 0:c0be4e018a09 | 114 | break; |
morita | 0:c0be4e018a09 | 115 | case 8: |
morita | 0:c0be4e018a09 | 116 | if(++R >= 31)RGB_state++; |
morita | 0:c0be4e018a09 | 117 | G = R; |
morita | 0:c0be4e018a09 | 118 | break; |
morita | 0:c0be4e018a09 | 119 | case 9: |
morita | 0:c0be4e018a09 | 120 | if(-- R== 0)RGB_state++; |
morita | 0:c0be4e018a09 | 121 | G = R; |
morita | 0:c0be4e018a09 | 122 | break; |
morita | 0:c0be4e018a09 | 123 | case 10: |
morita | 0:c0be4e018a09 | 124 | if(++G >= 31)RGB_state++; |
morita | 0:c0be4e018a09 | 125 | B = G; |
morita | 0:c0be4e018a09 | 126 | break; |
morita | 0:c0be4e018a09 | 127 | case 11: |
morita | 0:c0be4e018a09 | 128 | if(-- G== 0)RGB_state++; |
morita | 0:c0be4e018a09 | 129 | B = G; |
morita | 0:c0be4e018a09 | 130 | break; |
morita | 0:c0be4e018a09 | 131 | case 12: |
morita | 0:c0be4e018a09 | 132 | if(++R >= 31)RGB_state++; |
morita | 0:c0be4e018a09 | 133 | B = G = R; |
morita | 0:c0be4e018a09 | 134 | break; |
morita | 0:c0be4e018a09 | 135 | case 13: |
morita | 0:c0be4e018a09 | 136 | if(--R == 0)RGB_state = 0; |
morita | 0:c0be4e018a09 | 137 | B = G = R; |
morita | 0:c0be4e018a09 | 138 | break; |
morita | 0:c0be4e018a09 | 139 | } |
morita | 0:c0be4e018a09 | 140 | wait_ms(10); |
morita | 0:c0be4e018a09 | 141 | if(--tm==0){ |
morita | 0:c0be4e018a09 | 142 | tm=10; |
morita | 0:c0be4e018a09 | 143 | LED = LED ^ 1; |
morita | 0:c0be4e018a09 | 144 | } |
morita | 0:c0be4e018a09 | 145 | } |
morita | 0:c0be4e018a09 | 146 | } |