#include // Core graphics library #include // Hardware-specific library #define LCD_CS A3 // Chip Select goes to Analog 3 #define LCD_CD A2 // Command/Data goes to Analog 2, Labled LCD_RS #define LCD_WR A1 // LCD Write goes to Analog 1 #define LCD_RD A0 // LCD Read goes to Analog 0 #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin #define BLACK 0xFFFF //65523-65535 #define BLUE 0xFFE0 //65504-65522 #define BRIGHTBLUE 0xFD20 #define GREEN 0xF81F #define CYAN 0xF800 #define LIGHTBLUE 0xF400 #define BLUE2 0xAFE5 #define GRAY1 0x8410 #define RED 0x07FF //define BRIGHT_RED 0x???? #define GRAY2 0x4208 #define WHITE3 0x1000 #define W+PINK4 0x0D00 #define W+PINK3 0x0C00 #define W+PINK2 0x0B00 #define W+PINK 0x0A00 #define WHITE2 0x0800 #define MAGENTA 0x07E0 #define PINK3 0x0500 #define PINK2 0x0400 #define PINK 0x03E0 #define YELLOW 0x001F #define WHITE 0x0000 #define TESTCOL 0xF71F Adafruit_ILI9341_8bit_AS tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers float sdeg=0, mdeg=0, hdeg=0; uint16_t osx=120, osy=120, omx=120, omy=120, ohx=120, ohy=120; // Saved H, M, S x & y coords, was 64,64,64,64,64,64 uint16_t x0=0, x1=0, y0=0, y1=0; uint32_t targetTime = 0; // for next 1 second timeout uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6); // Get H, M, S from compile time void setup(void) { tft.reset(); delay(10); tft.begin(0x9341); //tft.fillScreen(BLACK); //Serial.begin(9600); tft.setRotation(0); tft.fillScreen(BLACK); tft.setTextSize(2); tft.setTextColor(WHITE, BLACK); // Adding a black background colour erases previous text automatically // Draw clock face tft.fillCircle(120, 120, 61, BLUE); //was 64,64,61 Blue tft.fillCircle(120, 120, 57, BLACK);// was 64, 64, 57, BLACK // Draw 12 lines for(int i = 0; i<360; i+= 30) { sx = cos((i-90)*0.0174532925); sy = sin((i-90)*0.0174532925); x0 = sx*57+120; // Was 57+64 y0 = sy*57+120; // Was 57+64 x1 = sx*50+120; // Was 50+64 y1 = sy*50+120; // Was 50+64 tft.drawLine(x0, y0, x1, y1, BLUE); } tft.fillCircle(120, 120, 3, RED);//was 65,65,3 Draws for Dot in Middle. tft.setCursor (55, 215); //was 34,151 Cursor for Date text. tft.print(__DATE__); // Print Date targetTime = millis() + 1000; // 1 Sec Update } void loop() { if (targetTime < millis()) { targetTime = millis()+1000; ss++; // Advance second if (ss==60) { ss=0; mm++; // Advance minute if(mm>59) { mm=0; hh++; // Advance hour if (hh>23) { hh=0; } } } // Pre-compute hand degrees, x & y coords for a fast screen update sdeg = ss*6; // 0-59 -> 0-354 mdeg = mm*6+sdeg*0.01666667; // 0-59 -> 0-360 - includes seconds hdeg = hh*30+mdeg*0.0833333; // 0-11 -> 0-360 - includes minutes and seconds hx = cos((hdeg-90)*0.0174532925); hy = sin((hdeg-90)*0.0174532925); mx = cos((mdeg-90)*0.0174532925); my = sin((mdeg-90)*0.0174532925); sx = cos((sdeg-90)*0.0174532925); sy = sin((sdeg-90)*0.0174532925); // Erase just old hand positions tft.drawLine(ohx, ohy, 120, 120, BLACK); //was 65,65 tft.drawLine(omx, omy, 120, 120, BLACK); //was 65,65 tft.drawLine(osx, osy, 120, 120, BLACK); //was 65,65 // Draw new hand positions tft.drawLine(hx*33+120, hy*33+120, 120, 120, WHITE);//was 33+65, 65,65,65 tft.drawLine(mx*44+120, my*44+120, 120, 120, WHITE);//was 44+65, 65,65,65 tft.drawLine(sx*47+120, sy*47+120, 120, 120, RED); //was 47+65, 65,65,65 tft.fillCircle(120, 120, 3, RED);//was 65,65,3 // Update old x&y coords osx = sx*47+120; osy = sy*47+120; // Was 47+65 47+65 omx = mx*44+120; omy = my*44+120; // Was 44+65 44+65 ohx = hx*33+120; ohy = hy*33+120; // Was 33+65 33+65 // Update digital time tft.setCursor (55, 195); // Digital time position. Was 34,140 if(hh>12) { if (hh<22) tft.print('0'); tft.print (hh-12); } else { if (hh<10) tft.print('0'); tft.print (hh); } tft.print (':'); if (mm<10) tft.print('0'); tft.print (mm); tft.print (':'); if (ss<10) tft.print('0'); tft.print (ss); if (hh>12) tft.print(" pm"); else tft.print (" am"); } } static uint8_t conv2d(const char* p) { uint8_t v = 0; if ('0' <= *p && *p <= '9') v = *p - '0'; return 10 * v + *++p - '0'; }