TFT rotation test program (ST7735) Using 1.8" Adafruit TFT Shield with Joystick and microSD v1.0 Verified by WIZwiki-W7500 platform
Dependencies: Adafruit_GFX Adafruit_ST7735 mbed
main.cpp@0:7315c6c53c24, 2015-07-28 (annotated)
- Committer:
- justinkim
- Date:
- Tue Jul 28 00:02:02 2015 +0000
- Revision:
- 0:7315c6c53c24
- Child:
- 1:b6cb79a9373d
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
justinkim | 0:7315c6c53c24 | 1 | #include "mbed.h" |
justinkim | 0:7315c6c53c24 | 2 | #include "Adafruit_ST7735.h" |
justinkim | 0:7315c6c53c24 | 3 | |
justinkim | 0:7315c6c53c24 | 4 | Adafruit_ST7735 tft(D11, D12, D13, D10, D8, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST |
justinkim | 0:7315c6c53c24 | 5 | Serial pc(USBTX, USBRX); |
justinkim | 0:7315c6c53c24 | 6 | |
justinkim | 0:7315c6c53c24 | 7 | void rotateLine(void); |
justinkim | 0:7315c6c53c24 | 8 | void rotateText(void); |
justinkim | 0:7315c6c53c24 | 9 | void rotatePixel(void); |
justinkim | 0:7315c6c53c24 | 10 | void rotateFastline(void); |
justinkim | 0:7315c6c53c24 | 11 | void rotateDrawrect(void); |
justinkim | 0:7315c6c53c24 | 12 | void rotateFillrect(void); |
justinkim | 0:7315c6c53c24 | 13 | void rotateDrawcircle(void); |
justinkim | 0:7315c6c53c24 | 14 | void rotateFillcircle(void); |
justinkim | 0:7315c6c53c24 | 15 | void rotateTriangle(void); |
justinkim | 0:7315c6c53c24 | 16 | void rotateFillTriangle(void); |
justinkim | 0:7315c6c53c24 | 17 | void rotateRoundRect(void); |
justinkim | 0:7315c6c53c24 | 18 | void rotateFillRoundRect(void); |
justinkim | 0:7315c6c53c24 | 19 | void rotateChar(void); |
justinkim | 0:7315c6c53c24 | 20 | void rotateString(void); |
justinkim | 0:7315c6c53c24 | 21 | |
justinkim | 0:7315c6c53c24 | 22 | int main(void) |
justinkim | 0:7315c6c53c24 | 23 | { |
justinkim | 0:7315c6c53c24 | 24 | pc.printf("Hello! Adafruit ST7735 rotation test\r\n"); |
justinkim | 0:7315c6c53c24 | 25 | |
justinkim | 0:7315c6c53c24 | 26 | // Use this initializer if you're using a 1.8" TFT |
justinkim | 0:7315c6c53c24 | 27 | tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab |
justinkim | 0:7315c6c53c24 | 28 | |
justinkim | 0:7315c6c53c24 | 29 | // Use this initializer (uncomment) if you're using a 1.44" TFT |
justinkim | 0:7315c6c53c24 | 30 | //tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab |
justinkim | 0:7315c6c53c24 | 31 | |
justinkim | 0:7315c6c53c24 | 32 | pc.printf("init\r\n"); |
justinkim | 0:7315c6c53c24 | 33 | |
justinkim | 0:7315c6c53c24 | 34 | tft.setTextWrap(false); // Allow text to run off right edge |
justinkim | 0:7315c6c53c24 | 35 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 36 | |
justinkim | 0:7315c6c53c24 | 37 | pc.printf("This is a test of the rotation capabilities of the TFT library!\r\n"); |
justinkim | 0:7315c6c53c24 | 38 | pc.printf("Press <SEND> (or type a character) to advance\r\n"); |
justinkim | 0:7315c6c53c24 | 39 | |
justinkim | 0:7315c6c53c24 | 40 | while(1) |
justinkim | 0:7315c6c53c24 | 41 | { |
justinkim | 0:7315c6c53c24 | 42 | rotateLine(); |
justinkim | 0:7315c6c53c24 | 43 | rotateText(); |
justinkim | 0:7315c6c53c24 | 44 | rotatePixel(); |
justinkim | 0:7315c6c53c24 | 45 | rotateFastline(); |
justinkim | 0:7315c6c53c24 | 46 | rotateDrawrect(); |
justinkim | 0:7315c6c53c24 | 47 | rotateFillrect(); |
justinkim | 0:7315c6c53c24 | 48 | rotateDrawcircle(); |
justinkim | 0:7315c6c53c24 | 49 | rotateFillcircle(); |
justinkim | 0:7315c6c53c24 | 50 | rotateTriangle(); |
justinkim | 0:7315c6c53c24 | 51 | rotateFillTriangle(); |
justinkim | 0:7315c6c53c24 | 52 | rotateRoundRect(); |
justinkim | 0:7315c6c53c24 | 53 | rotateFillRoundRect(); |
justinkim | 0:7315c6c53c24 | 54 | rotateChar(); |
justinkim | 0:7315c6c53c24 | 55 | rotateString(); |
justinkim | 0:7315c6c53c24 | 56 | } |
justinkim | 0:7315c6c53c24 | 57 | } |
justinkim | 0:7315c6c53c24 | 58 | |
justinkim | 0:7315c6c53c24 | 59 | void rotateLine(void) { |
justinkim | 0:7315c6c53c24 | 60 | char ch; |
justinkim | 0:7315c6c53c24 | 61 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 62 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 63 | |
justinkim | 0:7315c6c53c24 | 64 | tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, ST7735_RED); |
justinkim | 0:7315c6c53c24 | 65 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 66 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 67 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 68 | |
justinkim | 0:7315c6c53c24 | 69 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 70 | } |
justinkim | 0:7315c6c53c24 | 71 | } |
justinkim | 0:7315c6c53c24 | 72 | |
justinkim | 0:7315c6c53c24 | 73 | void rotateText(void) { |
justinkim | 0:7315c6c53c24 | 74 | char ch; |
justinkim | 0:7315c6c53c24 | 75 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 76 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 77 | |
justinkim | 0:7315c6c53c24 | 78 | tft.setCursor(0, 30); |
justinkim | 0:7315c6c53c24 | 79 | tft.setTextColor(ST7735_RED); |
justinkim | 0:7315c6c53c24 | 80 | tft.setTextSize(1); |
justinkim | 0:7315c6c53c24 | 81 | tft.printf("Hello World!\r\n"); |
justinkim | 0:7315c6c53c24 | 82 | tft.setTextColor(ST7735_YELLOW); |
justinkim | 0:7315c6c53c24 | 83 | tft.setTextSize(2); |
justinkim | 0:7315c6c53c24 | 84 | tft.printf("Hello World!\r\n"); |
justinkim | 0:7315c6c53c24 | 85 | tft.setTextColor(ST7735_GREEN); |
justinkim | 0:7315c6c53c24 | 86 | tft.setTextSize(3); |
justinkim | 0:7315c6c53c24 | 87 | tft.printf("Hello World!\r\n"); |
justinkim | 0:7315c6c53c24 | 88 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 89 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 90 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 91 | |
justinkim | 0:7315c6c53c24 | 92 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 93 | } |
justinkim | 0:7315c6c53c24 | 94 | } |
justinkim | 0:7315c6c53c24 | 95 | |
justinkim | 0:7315c6c53c24 | 96 | void rotatePixel(void) { |
justinkim | 0:7315c6c53c24 | 97 | char ch; |
justinkim | 0:7315c6c53c24 | 98 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 99 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 100 | |
justinkim | 0:7315c6c53c24 | 101 | tft.drawPixel(10,20, ST7735_WHITE); |
justinkim | 0:7315c6c53c24 | 102 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 103 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 104 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 105 | |
justinkim | 0:7315c6c53c24 | 106 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 107 | } |
justinkim | 0:7315c6c53c24 | 108 | } |
justinkim | 0:7315c6c53c24 | 109 | |
justinkim | 0:7315c6c53c24 | 110 | void rotateFastline(void) { |
justinkim | 0:7315c6c53c24 | 111 | char ch; |
justinkim | 0:7315c6c53c24 | 112 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 113 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 114 | |
justinkim | 0:7315c6c53c24 | 115 | tft.drawFastHLine(0, 20, tft.width(), ST7735_RED); |
justinkim | 0:7315c6c53c24 | 116 | tft.drawFastVLine(20, 0, tft.height(), ST7735_BLUE); |
justinkim | 0:7315c6c53c24 | 117 | |
justinkim | 0:7315c6c53c24 | 118 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 119 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 120 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 121 | |
justinkim | 0:7315c6c53c24 | 122 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 123 | } |
justinkim | 0:7315c6c53c24 | 124 | } |
justinkim | 0:7315c6c53c24 | 125 | |
justinkim | 0:7315c6c53c24 | 126 | void rotateDrawrect(void) { |
justinkim | 0:7315c6c53c24 | 127 | char ch; |
justinkim | 0:7315c6c53c24 | 128 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 129 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 130 | |
justinkim | 0:7315c6c53c24 | 131 | tft.drawRect(10, 20, 10, 20, ST7735_GREEN); |
justinkim | 0:7315c6c53c24 | 132 | |
justinkim | 0:7315c6c53c24 | 133 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 134 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 135 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 136 | |
justinkim | 0:7315c6c53c24 | 137 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 138 | } |
justinkim | 0:7315c6c53c24 | 139 | } |
justinkim | 0:7315c6c53c24 | 140 | |
justinkim | 0:7315c6c53c24 | 141 | void rotateFillrect(void) { |
justinkim | 0:7315c6c53c24 | 142 | char ch; |
justinkim | 0:7315c6c53c24 | 143 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 144 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 145 | |
justinkim | 0:7315c6c53c24 | 146 | tft.fillRect(10, 20, 10, 20, ST7735_GREEN); |
justinkim | 0:7315c6c53c24 | 147 | |
justinkim | 0:7315c6c53c24 | 148 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 149 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 150 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 151 | |
justinkim | 0:7315c6c53c24 | 152 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 153 | } |
justinkim | 0:7315c6c53c24 | 154 | } |
justinkim | 0:7315c6c53c24 | 155 | |
justinkim | 0:7315c6c53c24 | 156 | void rotateDrawcircle(void) { |
justinkim | 0:7315c6c53c24 | 157 | char ch; |
justinkim | 0:7315c6c53c24 | 158 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 159 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 160 | |
justinkim | 0:7315c6c53c24 | 161 | tft.drawCircle(10, 30, 10, ST7735_YELLOW); |
justinkim | 0:7315c6c53c24 | 162 | |
justinkim | 0:7315c6c53c24 | 163 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 164 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 165 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 166 | |
justinkim | 0:7315c6c53c24 | 167 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 168 | } |
justinkim | 0:7315c6c53c24 | 169 | } |
justinkim | 0:7315c6c53c24 | 170 | |
justinkim | 0:7315c6c53c24 | 171 | void rotateFillcircle(void) { |
justinkim | 0:7315c6c53c24 | 172 | char ch; |
justinkim | 0:7315c6c53c24 | 173 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 174 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 175 | |
justinkim | 0:7315c6c53c24 | 176 | tft.fillCircle(10, 30, 10, ST7735_YELLOW); |
justinkim | 0:7315c6c53c24 | 177 | |
justinkim | 0:7315c6c53c24 | 178 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 179 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 180 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 181 | |
justinkim | 0:7315c6c53c24 | 182 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 183 | } |
justinkim | 0:7315c6c53c24 | 184 | } |
justinkim | 0:7315c6c53c24 | 185 | |
justinkim | 0:7315c6c53c24 | 186 | void rotateTriangle(void) { |
justinkim | 0:7315c6c53c24 | 187 | char ch; |
justinkim | 0:7315c6c53c24 | 188 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 189 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 190 | |
justinkim | 0:7315c6c53c24 | 191 | tft.drawTriangle(20, 10, 10, 30, 30, 30, ST7735_GREEN); |
justinkim | 0:7315c6c53c24 | 192 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 193 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 194 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 195 | |
justinkim | 0:7315c6c53c24 | 196 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 197 | } |
justinkim | 0:7315c6c53c24 | 198 | } |
justinkim | 0:7315c6c53c24 | 199 | |
justinkim | 0:7315c6c53c24 | 200 | void rotateFillTriangle(void) { |
justinkim | 0:7315c6c53c24 | 201 | char ch; |
justinkim | 0:7315c6c53c24 | 202 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 203 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 204 | |
justinkim | 0:7315c6c53c24 | 205 | tft.fillTriangle(20, 10, 10, 30, 30, 30, ST7735_RED); |
justinkim | 0:7315c6c53c24 | 206 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 207 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 208 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 209 | |
justinkim | 0:7315c6c53c24 | 210 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 211 | } |
justinkim | 0:7315c6c53c24 | 212 | } |
justinkim | 0:7315c6c53c24 | 213 | |
justinkim | 0:7315c6c53c24 | 214 | void rotateRoundRect(void) { |
justinkim | 0:7315c6c53c24 | 215 | char ch; |
justinkim | 0:7315c6c53c24 | 216 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 217 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 218 | |
justinkim | 0:7315c6c53c24 | 219 | tft.drawRoundRect(20, 10, 25, 15, 5, ST7735_BLUE); |
justinkim | 0:7315c6c53c24 | 220 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 221 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 222 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 223 | |
justinkim | 0:7315c6c53c24 | 224 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 225 | } |
justinkim | 0:7315c6c53c24 | 226 | } |
justinkim | 0:7315c6c53c24 | 227 | |
justinkim | 0:7315c6c53c24 | 228 | void rotateFillRoundRect(void) { |
justinkim | 0:7315c6c53c24 | 229 | char ch; |
justinkim | 0:7315c6c53c24 | 230 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 231 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 232 | |
justinkim | 0:7315c6c53c24 | 233 | tft.fillRoundRect(20, 10, 25, 15, 5, ST7735_CYAN); |
justinkim | 0:7315c6c53c24 | 234 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 235 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 236 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 237 | |
justinkim | 0:7315c6c53c24 | 238 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 239 | } |
justinkim | 0:7315c6c53c24 | 240 | } |
justinkim | 0:7315c6c53c24 | 241 | |
justinkim | 0:7315c6c53c24 | 242 | void rotateChar(void) { |
justinkim | 0:7315c6c53c24 | 243 | char ch; |
justinkim | 0:7315c6c53c24 | 244 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 245 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 246 | |
justinkim | 0:7315c6c53c24 | 247 | tft.drawChar(25, 15, 'A', ST7735_WHITE, ST7735_WHITE, 1); |
justinkim | 0:7315c6c53c24 | 248 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 249 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 250 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 251 | |
justinkim | 0:7315c6c53c24 | 252 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 253 | } |
justinkim | 0:7315c6c53c24 | 254 | } |
justinkim | 0:7315c6c53c24 | 255 | |
justinkim | 0:7315c6c53c24 | 256 | void rotateString(void) { |
justinkim | 0:7315c6c53c24 | 257 | char ch; |
justinkim | 0:7315c6c53c24 | 258 | for (uint8_t i=0; i<4; i++) { |
justinkim | 0:7315c6c53c24 | 259 | tft.fillScreen(ST7735_BLACK); |
justinkim | 0:7315c6c53c24 | 260 | |
justinkim | 0:7315c6c53c24 | 261 | tft.setCursor(8, 25); |
justinkim | 0:7315c6c53c24 | 262 | tft.setTextSize(1); |
justinkim | 0:7315c6c53c24 | 263 | tft.setTextColor(ST7735_WHITE); |
justinkim | 0:7315c6c53c24 | 264 | tft.printf("Adafruit Industries"); |
justinkim | 0:7315c6c53c24 | 265 | while (pc.readable()); |
justinkim | 0:7315c6c53c24 | 266 | ch=pc.getc(); |
justinkim | 0:7315c6c53c24 | 267 | pc.printf("%c\r\n",ch); |
justinkim | 0:7315c6c53c24 | 268 | |
justinkim | 0:7315c6c53c24 | 269 | tft.setRotation(tft.getRotation()+1); |
justinkim | 0:7315c6c53c24 | 270 | } |
justinkim | 0:7315c6c53c24 | 271 | } |