#include <U8g2lib.h>
#include <Wire.h>
#include <TimeLib.h>
U8G2_ILI9341_240X320_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
void drawClock() {
int sVal = second();
int mVal = minute();
int hVal = hour() % 12;
// Clear the buffer
u8g2.clearBuffer();
// Draw clock face
u8g2.drawCircle(120, 160, 120);
// Draw hour hand
u8g2.drawLine(120, 160, 120 + 60 * cos((hVal * 30 + mVal / 2.0) * PI / 180), 160 + 60 * sin((hVal * 30 + mVal / 2.0) * PI / 180));
// Draw minute hand
u8g2.drawLine(120, 160, 120 + 80 * cos((mVal * 6 + sVal / 10.0) * PI / 180), 160 + 80 * sin((mVal * 6 + sVal / 10.0) * PI / 180));
// Draw second hand
u8g2.setColorIndex(1);
u8g2.drawLine(120, 160, 120 + 100 * cos(sVal * 6 * PI / 180), 160 + 100 * sin(sVal * 6 * PI / 180));
u8g2.setColorIndex(0);
// Send the buffer to the display
u8g2.sendBuffer();
}
void setup(void) {
// Initialize ILI9341
u8g2.begin();
// Set font
u8g2.setFont(u8g2_font_unifont_t_symbols);
// Initialize Time library
setTime(0, 0, 0, 1, 1, 2023);
}
void loop(void) {
drawClock();
// Refresh display
u8g2.setCursor(5, 312);
u8g2.print("Analog Clock");
// Update every second
delay(1000);
// Update Time library
adjustTime(1);
}
drawing hyperbola ia a mathematicscodes from ai by arvind.
अरविन्द पाटील 1/12/23 .