/*
  Arduino | coding-help
  Why is it not displaying the day but
  instead im getting these weird symbols?

  Plumbkin — 6/24/24 at 11:00 PM
  Im trying to make a plotter and now im trying to integrate
  a rtc d1302 but im not getting the day but these symbols
  or something. The code is in void Loop () .
  I'd like your help and expertise on this as I am just starting
  to code in arduino and I hope to get an explanation and some
  tip or shortcut on my code. Thank you.
*/

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

#define TFT_DC 9
#define TFT_CS 10
#define BLACK   0x0000
#define BBLACK  0x7bcf
#define WHITE   0xFFFF
#define RED     0xF800
#define GREEN   0x07E0
#define BLUE    0x001F
#define YELLOW  0xFFE0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define LPINK   0xf99c
#define LAV     0xddff
#define BBLUE   0x049f
#define NAVY    0x000e
#define LPURPLE 0xddff
#define LIME    0xbf68
#define OLIVE   0x8400
#define BROWN   0x9b04

char daysOfTheWeek[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};


RTC_DS1307 rtc;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

void setup() {
  Serial.begin(115200);
  tft.begin();
  rtc.begin();

  tft.setRotation(1);
  tft.setTextSize(1);
  tft.setTextColor(BLACK);
  tft.fillScreen(WHITE);
  tft.drawLine(240, 0, 240, 320, BLACK);
  tft.drawLine(0, 160, 480, 160, BLACK);

  for (int x = 10; x <= 480; x += 20) {
    if (x == 240) continue;
    tft.drawLine(x,  0, x, 320, YELLOW);
  }
  for (int y = 10; y <= 320; y += 20) {
    if (y == 160) continue;
    tft.drawLine(0, y, 480, y, BLACK);
  }
  for (int x = 10; x <= 480; x += 20) {
    if (x == 240) continue;
    tft.drawLine(x,  0, x, 320, YELLOW);
  }
  for (int y = 10; y <= 320; y += 20) {
    if (y == 160) continue;
    tft.drawLine(0, y, 480, y, YELLOW);
  }

  // submain 1 f
  for (int y = 0; y <= 320; y += 20)  {
    if (y == 160) continue;
    tft.drawLine(0, y, 480, y, LPURPLE);
  }
  for (int x = 0; x <= 480; x += 20)  {
    if (x == 240) continue;
    tft.drawLine(x, 0, x, 320, LPURPLE);
  }

  // Origin
  int x = 232;
  int y = 162;
  tft.setCursor(x, y);
  tft.print("0");
  // X AXIS
  int label = -1;
  for (int xAxis = x - 20; xAxis >= 2; xAxis -= 20) {
    tft.setCursor(xAxis, y);
    tft.print(label);
    label = label - 1;
  }
  label = 1;
  for (int xAxis = x + 20; xAxis <= 402; xAxis += 20) {
    tft.setCursor(xAxis, y);
    tft.print(label);
    label = label + 1;
  }
  /*
    int x = 202;
    int y = 162;
    tft.setCursor(x, y);
    tft.print(-1);
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-2");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-3");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-4");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-5");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-6");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-7");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-8");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-9");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-10");
    x -= 20;
    tft.setCursor(x, y);
    tft.print("-11");

    int x1 = 262;
    int y1 = 162;
    tft.setCursor(x1, y1);
    tft.print("1");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("2");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("3");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("4");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("5");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("6");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("7");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("8");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("9");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("10");
    x1 += 20;
    tft.setCursor(x1, y1);
    tft.print("11");
  */
  // Y AXIS

  int x2 = 225;
  int y2 = 182;
  tft.setCursor(x2, y2);
  tft.print("-1");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-2");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-3");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-4");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-5");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-6");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-7");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-8");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-9");
  y2 += 20;
  tft.setCursor(x2, y2);
  tft.print("-10");
  y2 += 20;

  int x3 = 230; // Starting x-coordinate
  int y3 = 132; // y-coordinate
  tft.setCursor(x3, y3);
  // Print numbers manually while adjusting x-coordinate

  tft.print("1");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("2");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("3");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("4");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("5");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("6");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("7");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("8");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("9");
  y3 -= 20;
  tft.setCursor(x3, y3);
  tft.print("10");
  y3 -= 20;

  //VALUE OF PLOT // SET // Plotter
  tft.fillRoundRect(360, 300, 460, 320, 5, WHITE);
  tft.fillRoundRect(400, 5, 475, 85,  5, WHITE);
  tft.fillRoundRect(0, 5, 100, 20, 2, WHITE);
  tft.drawRoundRect(360, 300,  460, 320, 5, BLACK);
  tft.drawRoundRect(400, 5, 475, 85, 5, BLACK);
  tft.drawRoundRect(0, 5, 100, 20, 2, BLACK);
  tft.drawLine(5, 10, 10, 10, BLACK);
  tft.drawLine(5, 12, 10, 12, BLACK);
  tft.drawLine(5, 14, 10, 14, BLACK);

  tft.setTextSize(1);
  tft.setTextColor(BLACK);
  tft.setCursor(30, 10);
  tft.print("Plotter");
  // 1st Set
  tft.fillCircle(410, 15, 3, RED);
  tft.print("SET");
  tft.setTextColor(BLUE);
  tft.setCursor(420, 22);
  tft.print("SET");
  tft.fillCircle(410, 25, 3, RED);
  tft.fillCircle(410, 35, 3, GREEN);
  tft.setCursor(420, 22);
  tft.print("SET");
  tft.fillCircle(410, 45, 3, CYAN);
  tft.setCursor(420, 42);
  tft.print("SET");
  tft.fillCircle(410, 55, 3, YELLOW);
  tft.setCursor(420, 52);
  tft.print("SET");
  tft.fillCircle(410, 65, 3, MAGENTA);
  tft.setCursor(420, 62);
  tft.print("SET");
  tft.fillCircle(410, 75, 3, LPINK);
  tft.setCursor(420, 72);
  tft.print("SET");

  // 2nd Set

  //tft.setColor(LAV);
  tft.fillCircle(445, 15, 3, LAV);
  tft.setCursor(455, 12);
  tft.print("SET");
  //tft.setColor(BROWN);
  tft.fillCircle(445, 25, 3, BROWN);
  tft.setCursor(455, 22);
  tft.print("SET");
  //tft.setColor(BBLUE);
  tft.fillCircle(445, 35, 3, BBLUE);
  tft.setCursor(455, 32);
  tft.print("SET");
  //tft.setColor(NAVY);
  tft.fillCircle(445, 45, 3, NAVY);
  tft.setCursor(455, 42);
  tft.print("SET");
  //tft.setColor(LPURPLE);
  tft.fillCircle(445, 55, 3, LPURPLE);
  tft.setCursor(455, 52);
  tft.print("SET");
  //tft.setColor(LIME);
  tft.fillCircle(445, 65, 3, LIME);
  tft.setCursor(455, 62);
  tft.print("SET");
  //tft.setColor(OLIVE);
  tft.fillCircle(445, 75, 3, OLIVE);
  tft.setCursor(455, 72);
  tft.print("SET");
}

void loop() {

  // RTC
  //RtcDateTime now = Rtc.GetDateTime();
  DateTime now = rtc.now();
  tft.setTextSize(2);
  tft.setTextColor(BLACK, WHITE);
  tft.setCursor(20, 180);
  tft.print(now.hour());
  tft.print(":");
  if (now.minute() < 10) tft.print("0");
  tft.print(now.minute());
  tft.print(":");
  if (now.second() < 10) tft.print("0");
  tft.print(now.second());
  //int HOUR = now.hour();
  //int lol = "1";
  tft.setCursor(20, 200);
  tft.print(daysOfTheWeek[now.dayOfTheWeek()]);
  tft.setCursor(20, 220);
  tft.print(now.month());
  tft.print("/");
  tft.print(now.day());
  tft.print("/");
  tft.print(now.year());

  // Plots
  tft.setTextSize(1);
  //tft.setColor(RED);
  tft.fillCircle(260, 180, 2, RED);
  tft.setCursor(265, 180);
  tft.print("( 1,-1)");
  //tft.setColor(BLUE);
  tft.fillCircle(220, 180, 2, BLUE);
  tft.setCursor(170, 180);
  tft.print("(-1,-1)");
  //tft.setColor(GREEN);
  tft.fillCircle(260, 140, 2, GREEN);
  tft.setCursor(265, 140);
  tft.print("( 1, 1)");
  //tft.setColor(YELLOW);
  tft.fillCircle(220, 140, 2, YELLOW);
  tft.setCursor(170, 140);
  tft.print("(-1, 1)");

  tft.drawLine(220, 140, 260, 180, BLUE);


}
GND5VSDASCLSQWRTCDS1307+