Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **TFT Clock**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-09 11:17:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* print a clock on display. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <ILI9488.h> //https://github.com/jaretburkett/ILI9488
- #include <U8g2_for_Adafruit_GFX.h> //https://github.com/olikraus/U8g2_for_Adafruit_GFX
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void displayClock(); // Function to display the clock
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t display_ILI9488_TFT_RST_PIN_D2 = 2;
- const uint8_t display_ILI9488_TFT_DC_PIN_D3 = 3;
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t display_ILI9488_TFT_SPI_PIN_MOSI_D11 = 11;
- const uint8_t display_ILI9488_TFT_SPI_PIN_MISO_D12 = 12;
- const uint8_t display_ILI9488_TFT_SPI_PIN_SCLK_D13 = 13;
- const uint8_t display_ILI9488_TFT_SPI_PIN_CS_D10 = 10;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool display_ILI9488_TFT_RST_PIN_D2_rawData = 0;
- bool display_ILI9488_TFT_DC_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float display_ILI9488_TFT_RST_PIN_D2_phyData = 0.0;
- float display_ILI9488_TFT_DC_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the display
- ILI9488 display(display_ILI9488_TFT_SPI_PIN_CS_D10, display_ILI9488_TFT_DC_PIN_D3, display_ILI9488_TFT_SPI_PIN_MOSI_D11, display_ILI9488_TFT_SPI_PIN_SCLK_D13, display_ILI9488_TFT_RST_PIN_D2);
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(display_ILI9488_TFT_RST_PIN_D2, OUTPUT);
- pinMode(display_ILI9488_TFT_DC_PIN_D3, OUTPUT);
- pinMode(display_ILI9488_TFT_SPI_PIN_CS_D10, OUTPUT);
- // start the SPI library:
- SPI.begin();
- // Initialize the display
- display.begin();
- display.fillScreen(ILI9488_BLACK); // Clear screen with black color
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- displayClock(); // Display the current time
- }
- /****** FUNCTION TO UPDATE OUTPUTS *****/
- void updateOutputs()
- {
- digitalWrite(display_ILI9488_TFT_RST_PIN_D2, display_ILI9488_TFT_RST_PIN_D2_rawData);
- digitalWrite(display_ILI9488_TFT_DC_PIN_D3, display_ILI9488_TFT_DC_PIN_D3_rawData);
- }
- /****** FUNCTION TO DISPLAY CLOCK *****/
- void displayClock()
- {
- // Get current time
- unsigned long currentMillis = millis(); // Get the current time in milliseconds
- int seconds = (currentMillis / 1000) % 60; // Calculate seconds
- int minutes = (currentMillis / (1000 * 60)) % 60; // Calculate minutes
- int hours = (currentMillis / (1000 * 60 * 60)) % 24; // Calculate hours
- // Prepare the time string
- char timeString[9]; // HH:MM:SS
- sprintf(timeString, "%02d:%02d:%02d", hours, minutes, seconds);
- // Display the time on the screen
- display.setCursor(10, 50); // Set cursor position
- display.setTextColor(ILI9488_WHITE); // Set text color to white
- display.setTextSize(2); // Set text size
- display.print(timeString); // Print the time string
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement