#include <Adafruit_ILI9341.h>
#include "Fonts/FreeSerif9pt7b.h"
Adafruit_ILI9341 tft(10, 9);
uint16_t adjustBrightness(uint16_t color, int brightness) {
uint8_t r = color >> 11;
uint8_t g = (color >> 5) & 0x3f;
uint8_t b = color & 0x1f;
r = (r*brightness)/100;
g = (g*brightness)/100;
b = (b*brightness)/100;
return (r << 11) | (g << 5) | b;
}
void setup() {
Serial.begin(115200);
tft.begin();
tft.setFont(&FreeSerif9pt7b);
tft.setCursor(25, 160);
String msg = "Initialized Successfully!!";
for(int i=0; i<msg.length(); i++) {
tft.print(msg[i]);
delay(70);
}
delay(1000);
tft.setCursor(25, 160);
tft.setTextColor(0x0);
tft.print(msg);
}
void loop() {
for(int i=0; i<360; i+=2) {
float rad = (i*3.14)/180;
int x = 100*cos(rad);
int y = 100*sin(rad);
tft.drawLine(120, 160, x+120, y+160, adjustBrightness(0xffe0, ((i%6)*100)/6));
}
for(int i=0; i<360; i++)
tft.fillCircle(120+45*cos(((i-90)*3.14)/180), 160+45*sin(((i-90)*3.14)/180), 12, 0x0);
for(int i=0; i<360; i+=90)
tft.fillCircle(120+54*cos(((i-90)*3.14)/180), 160+54*sin(((i-90)*3.14)/180), 2, 0xffff);
for(int i=0; i<360; i+=30) {
tft.drawLine(120+58*cos(((i-90)*3.14)/180), 160+58*sin(((i-90)*3.14)/180), 120+100*cos(((i-90)*3.14)/180), 160+100*sin(((i-90)*3.14)/180), 0xf81f);
}
tft.setTextColor(0xffff);
tft.setCursor(110, 122);
tft.print("XII");
tft.setCursor(112, 208);
tft.print("VI");
tft.setCursor(152, 165);
tft.print("III");
tft.setCursor(72, 165);
tft.print("IX");
//tft.print()
float s=0, m=0, h=0;
int hr = 9, min = 35, sec = 00;
s = sec*6; m = min*6 + ((s*6)/360); h = hr*30 + ((m*30)/360);
for(int i=0; i<s; i++)
tft.fillCircle(120+99*cos(((i-90)*3.14)/180), 160+99*sin(((i-90)*3.14)/180), 3, 0xff00);
for(int i=0; i<m; i++)
tft.fillCircle(120+85*cos(((i-90)*3.14)/180), 160+85*sin(((i-90)*3.14)/180), 3, 0x7ff);
for(int i=0; i<h; i++)
tft.fillCircle(120+70*cos(((i-90)*3.14)/180), 160+70*sin(((i-90)*3.14)/180), 3, 0x7e0);
int error = 0;
while(1) {
unsigned long startTime = millis();
float rad_s = ((s-90)*3.14)/180;
float rad_m = ((m-90)*3.14)/180;
float rad_h = ((h-90)*3.14)/180;
tft.fillCircle(120+99*cos(rad_s), 160+99*sin(rad_s), 3, 0xff00);
tft.fillCircle(120+85*cos(rad_m), 160+85*sin(rad_m), 3, 0x7ff);
tft.fillCircle(120+70*cos(rad_h), 160+70*sin(rad_h), 3, 0x7e0);
Serial.print("m before : ");
Serial.println(m,6);
s+=1.5;
m += 0.025;
if(s == 360) h += 0.5;
Serial.println(s,6);
Serial.println(round(m) == 360);
Serial.println(h == 360);
if((s == 360) && (round(m) == 360) && (h == 360)) {
s = 0; m = 0; h = 0;
for(int i=-90; i<270; i+=3) {
tft.fillCircle(120+99*cos((i*3.14)/180), 160+99*sin((i*3.14)/180), 5, 0x0);
tft.fillCircle(120+85*cos((i*3.14)/180), 160+85*sin((i*3.14)/180), 4, 0x0);
tft.fillCircle(120+70*cos((i*3.14)/180), 160+70*sin((i*3.14)/180), 4, 0x0);
}
}
else if((s == 360) && (round(m) == 360)) {
s = 0; m = 0;
for(int i=-90; i<270; i+=3) {
tft.fillCircle(120+99*cos((i*3.14)/180), 160+99*sin((i*3.14)/180), 5, 0x0);
tft.fillCircle(120+85*cos((i*3.14)/180), 160+85*sin((i*3.14)/180), 4, 0x0);
}
}
else if(s == 360) {
s = 0;
for(int i=-90; i<270; i+=3) {
tft.fillCircle(120+99*cos((i*3.14)/180), 160+99*sin((i*3.14)/180), 5, 0x0);
}
}
unsigned long timeSpent = millis() - startTime;
Serial.print("Time spent : ");
Serial.println(timeSpent);
if(250 < timeSpent) {
error += timeSpent - 250;
} else {
delay(250 - timeSpent - error);
Serial.print("delay : ");
Serial.println(250-timeSpent-error);
error = 0;
}
Serial.print("error : ");
Serial.println(error);
Serial.println("");
}
}