Error in time library in making clock

I have trouble, I installed time library but still getHours was not decleard.

#include <UTFT.h>
#include <URTouch.h>

// Define the pins for your touch screen
#define TFT_RST A4
#define TFT_RS A3
#define TFT_CS A2
#define TFT_WR A1
#define TFT_RD A0
#define TOUCH_XP A2
#define TOUCH_YP A3
#define TOUCH_XM A1
#define TOUCH_YM A0

// Define the screen dimensions and colors
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240

#define CLOCK_POSITION_X 20
#define CLOCK_POSITION_Y 20

// Define the file explorer dimensions and colors
#define FILE_EXPLORER_POSITION_X 50
#define FILE_EXPLORER_POSITION_Y 50
#define FILE_EXPLORER_WIDTH 200
#define FILE_EXPLORER_HEIGHT 150

// Create an instance of the library for the TFT screen
UTFT myGLCD(TFT_RD, TFT_WR, TFT_RS, TFT_CS, TFT_RST);

// Create an instance of the library for the touch screen
URTouch myTouch(TOUCH_XP, TOUCH_YP, TOUCH_XM, TOUCH_YM, 300);

// Function to draw the clock widget
void drawClock() {
// Get the current time and date
int hours = getHours();
int minutes = getMinutes();
int seconds = getSeconds();
int day = getDay();

int month = getMonth();
int year = getYear();

// Draw the clock widget on the screen

myGLCD.print(hours, CLOCK_POSITION_X, CLOCK_POSITION_Y);
myGLCD.print(":", CLOCK_POSITION_X + 70, CLOCK_POSITION_Y);
myGLCD.print(minutes, CLOCK_POSITION_X + 90, CLOCK_POSITION_Y);
myGLCD.print(":", CLOCK_POSITION_X + 160, CLOCK_POSITION_Y);
myGLCD.print(seconds, CLOCK_POSITION_X + 180, CLOCK_POSITION_Y);

// Draw the date

myGLCD.print(day, CLOCK_POSITION_X + 50, CLOCK_POSITION_Y + 30);
myGLCD.print("/", CLOCK_POSITION_X + 70, CLOCK_POSITION_Y + 30);
myGLCD.print(month, CLOCK_POSITION_X + 90, CLOCK_POSITION_Y + 30);
myGLCD.print("/", CLOCK_POSITION_X + 110, CLOCK_POSITION_Y + 30);
myGLCD.print(year, CLOCK_POSITION_X + 130, CLOCK_POSITION_Y + 30);
}

// Function to draw the file explorer widget
void drawFileExplorer() {
// Draw the file explorer widget on the screen

myGLCD.fillRoundRect(FILE_EXPLORER_POSITION_X, FILE_EXPLORER_POSITION_Y, FILE_EXPLORER_POSITION_X + FILE_EXPLORER_WIDTH, FILE_EXPLORER_POSITION_Y + FILE_EXPLORER_HEIGHT );

myGLCD.print("File Explorer", FILE_EXPLORER_POSITION_X + 10,
FILE_EXPLORER_POSITION_Y + 10);

// Display the files and folders in the file explorer
// You will need to modify this based on your specific file system
// You can use the myGLCD.print() function to display the file and folder names
}

void setup() {
// Initialize the TFT screen
myGLCD.InitLCD();
myGLCD.clrScr();

// Initialize the touch screen
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);

}

void loop() {
// Check for touch input
if (myTouch.dataAvailable()) {
// Read the touch input
myTouch.read();

// Check if the touch input corresponds to the clock widget
if (myTouch.getX() >= CLOCK_POSITION_X &&
    myTouch.getX() <= CLOCK_POSITION_X + 200 &&
    myTouch.getY() >= CLOCK_POSITION_Y &&
    myTouch.getY() <= CLOCK_POSITION_Y + 100) {
  // Perform actions when clock widget is touched
  // For example, display a menu or perform a specific action
}

// Check if the touch input corresponds to the file explorer widget
if (myTouch.getX() >= FILE_EXPLORER_POSITION_X &&
    myTouch.getX() <= FILE_EXPLORER_POSITION_X + FILE_EXPLORER_WIDTH &&
    myTouch.getY() >= FILE_EXPLORER_POSITION_Y &&
    myTouch.getY() <= FILE_EXPLORER_POSITION_Y + FILE_EXPLORER_HEIGHT) {
  // Perform actions when file explorer widget is touched
  // For example, navigate through folders or open a file
}

}

// Update the clock widget every second
if (millis() % 1000 == 0) {
drawClock();
}
}
// it takes 10 hours to make code but still errors

Who created the sketch?

Have you looked at the examples of the Uptime library?

meoww

can you please cheek the code

I tried but failed

What is the meaning of this ?

meaning I made

Ok, this is proper point to get started.

Use a logic analyzer to see what happens.

Insert Serial.println()´s at points of interrest and analyze the test results.

Have a nice day and enjoy coding in C++.

1 Like

Fpr a code that does not compile?

Look again. What do they do in the example? I can't remember which one I looked at but the example starts with an include to include the the library first and later creates an Uptime object.

The object has access to the methods like getHours().

libray issue

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.