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
Diff: main.cpp
- Revision:
- 1:b6cb79a9373d
- Parent:
- 0:7315c6c53c24
diff -r 7315c6c53c24 -r b6cb79a9373d main.cpp --- a/main.cpp Tue Jul 28 00:02:02 2015 +0000 +++ b/main.cpp Thu Jul 30 22:59:09 2015 +0000 @@ -1,9 +1,17 @@ #include "mbed.h" #include "Adafruit_ST7735.h" +#define BUTTON_NONE 0 +#define BUTTON_DOWN 1 +#define BUTTON_RIGHT 2 +#define BUTTON_SELECT 3 +#define BUTTON_UP 4 +#define BUTTON_LEFT 5 + Adafruit_ST7735 tft(D11, D12, D13, D10, D8, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST -Serial pc(USBTX, USBRX); +AnalogIn joystick(A3); +uint8_t readButton(void); void rotateLine(void); void rotateText(void); void rotatePixel(void); @@ -20,8 +28,8 @@ void rotateString(void); int main(void) -{ - pc.printf("Hello! Adafruit ST7735 rotation test\r\n"); +{ + printf("Hello! Adafruit ST7735 rotation test\r\n"); // Use this initializer if you're using a 1.8" TFT tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab @@ -29,16 +37,16 @@ // Use this initializer (uncomment) if you're using a 1.44" TFT //tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab - pc.printf("init\r\n"); + printf("init\r\n"); tft.setTextWrap(false); // Allow text to run off right edge tft.fillScreen(ST7735_BLACK); - pc.printf("This is a test of the rotation capabilities of the TFT library!\r\n"); - pc.printf("Press <SEND> (or type a character) to advance\r\n"); + printf("This is a test of the rotation capabilities of the TFT library!\r\n"); + printf("Press <SEND> (or type a character) to advance\r\n"); while(1) - { + { rotateLine(); rotateText(); rotatePixel(); @@ -57,22 +65,33 @@ } void rotateLine(void) { - char ch; + + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, ST7735_RED); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); - + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } + tft.setRotation(tft.getRotation()+1); } } void rotateText(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.setCursor(0, 30); @@ -85,187 +104,272 @@ tft.setTextColor(ST7735_GREEN); tft.setTextSize(3); tft.printf("Hello World!\r\n"); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); - + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotatePixel(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.drawPixel(10,20, ST7735_WHITE); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateFastline(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.drawFastHLine(0, 20, tft.width(), ST7735_RED); tft.drawFastVLine(20, 0, tft.height(), ST7735_BLUE); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateDrawrect(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.drawRect(10, 20, 10, 20, ST7735_GREEN); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateFillrect(void) { - char ch; + uint8_t a = 0,b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.fillRect(10, 20, 10, 20, ST7735_GREEN); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateDrawcircle(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.drawCircle(10, 30, 10, ST7735_YELLOW); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); - + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } + tft.setRotation(tft.getRotation()+1); } } void rotateFillcircle(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.fillCircle(10, 30, 10, ST7735_YELLOW); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateTriangle(void) { - char ch; - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(ST7735_BLACK); + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; + tft.fillScreen(ST7735_BLACK); tft.drawTriangle(20, 10, 10, 30, 30, 30, ST7735_GREEN); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateFillTriangle(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); - tft.fillTriangle(20, 10, 10, 30, 30, 30, ST7735_RED); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateRoundRect(void) { - char ch; - for (uint8_t i=0; i<4; i++) { - tft.fillScreen(ST7735_BLACK); + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; + tft.fillScreen(ST7735_BLACK); tft.drawRoundRect(20, 10, 25, 15, 5, ST7735_BLUE); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateFillRoundRect(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.fillRoundRect(20, 10, 25, 15, 5, ST7735_CYAN); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); - + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } + tft.setRotation(tft.getRotation()+1); } } void rotateChar(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.drawChar(25, 15, 'A', ST7735_WHITE, ST7735_WHITE, 1); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } void rotateString(void) { - char ch; + uint8_t a = 0, b; + + b = readButton(); + for (uint8_t i=0; i<4; i++) { + a = 1; tft.fillScreen(ST7735_BLACK); tft.setCursor(8, 25); tft.setTextSize(1); tft.setTextColor(ST7735_WHITE); tft.printf("Adafruit Industries"); - while (pc.readable()); - ch=pc.getc(); - pc.printf("%c\r\n",ch); + while (a){ + b = readButton(); + if(b==BUTTON_SELECT) + a = 0; + } tft.setRotation(tft.getRotation()+1); } } + +uint8_t readButton(void) { + float a = joystick.read(); + + a *= 5.0; + + printf("Button read analog = %f\r\n",a); + if (a < 0.2) return BUTTON_DOWN; + if (a < 1.0) return BUTTON_RIGHT; + if (a < 1.7) return BUTTON_SELECT; + if (a < 2.6) return BUTTON_UP; + if (a < 4.6) return BUTTON_LEFT; + else return BUTTON_NONE; +} +