#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <SPI.h>


#define TFT_RST  6
#define TFT_DC   5
#define TFT_CS   10
#define TFT_MOSI 11
#define TFT_MISO 12
#define TFT_CLK 13


Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

int16_t r;   // determines the radius of the corner
int16_t x;   // horizontal starting position
int16_t y;   // verticle starting postion
int16_t w;   // width
int16_t h;  // height
int color;

void drawTheThing(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, int color) {
  int i = 0;
  int lH = 1;
  tft.fillRect((x + r - 1), y, (w - 2 * r + 2), lH, color);
  for (i = 1; i < (r - 2); i++) {
    tft.fillRect((x + r - 2 - i), (y + i), (w + 2 * i - 2 * r + 4), lH, color);
    tft.fillRect((x + i), (y + i + h - r + 1), (w - 2 * i), lH, color);
  }
  tft.fillRect((x + r - i - 1), (y + i), (w + 2 * i - 2 * r + 2), lH, color);
  tft.fillRect((x + r - i - 2), (y + i + 1), (w + 2 * i - 2 * r + 4), lH, color);
  tft.fillRect((x + r - i - 2), (y + i + 2), (w + 2 * i - 2 * r + 4), (h - 2 * r + 1), color);
  tft.fillRect((x + 1), (y + h - r + 1), (w - 2), lH, color);
  tft.fillRect((x + i + 1), (y + i - r + h + 1), (w - 2 * i - 2), lH, color);
  i = 0;
}



void setup() {
  // put your setup code here, to run once:

  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  drawTheThing(10, 10, 100, 300, 7, ILI9341_GREEN); // Custom function
  tft.fillRoundRect(130, 10, 100, 300, 8, ILI9341_RED); // Builtin to Adafruit_GFX


}

void loop() {
  // put your main code here, to run repeatedly:

}