Advertisement
pleasedontcode

**TFT Clock** rev_03

Dec 9th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **TFT Clock**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-09 11:17:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* print a clock on display. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <SPI.h>
  27. #include <ILI9488.h>    //https://github.com/jaretburkett/ILI9488
  28. #include <U8g2_for_Adafruit_GFX.h>  //https://github.com/olikraus/U8g2_for_Adafruit_GFX
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs();
  34. void displayClock(); // Function to display the clock
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t display_ILI9488_TFT_RST_PIN_D2        = 2;
  38. const uint8_t display_ILI9488_TFT_DC_PIN_D3     = 3;
  39.  
  40. /***** DEFINITION OF SPI PINS *****/
  41. const uint8_t display_ILI9488_TFT_SPI_PIN_MOSI_D11      = 11;
  42. const uint8_t display_ILI9488_TFT_SPI_PIN_MISO_D12      = 12;
  43. const uint8_t display_ILI9488_TFT_SPI_PIN_SCLK_D13      = 13;
  44. const uint8_t display_ILI9488_TFT_SPI_PIN_CS_D10        = 10;
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. bool    display_ILI9488_TFT_RST_PIN_D2_rawData      = 0;
  48. bool    display_ILI9488_TFT_DC_PIN_D3_rawData       = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. float   display_ILI9488_TFT_RST_PIN_D2_phyData      = 0.0;
  52. float   display_ILI9488_TFT_DC_PIN_D3_phyData       = 0.0;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. // Create an instance of the display
  56. 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);
  57.  
  58. /****** SETUP FUNCTION *****/
  59. void setup(void)
  60. {
  61.     // put your setup code here, to run once:
  62.     pinMode(display_ILI9488_TFT_RST_PIN_D2, OUTPUT);
  63.     pinMode(display_ILI9488_TFT_DC_PIN_D3, OUTPUT);
  64.     pinMode(display_ILI9488_TFT_SPI_PIN_CS_D10, OUTPUT);
  65.    
  66.     // start the SPI library:
  67.     SPI.begin();
  68.    
  69.     // Initialize the display
  70.     display.begin();
  71.     display.fillScreen(ILI9488_BLACK); // Clear screen with black color
  72. }
  73.  
  74. /****** LOOP FUNCTION *****/
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.     updateOutputs(); // Refresh output data
  79.     displayClock(); // Display the current time
  80. }
  81.  
  82. /****** FUNCTION TO UPDATE OUTPUTS *****/
  83. void updateOutputs()
  84. {
  85.     digitalWrite(display_ILI9488_TFT_RST_PIN_D2, display_ILI9488_TFT_RST_PIN_D2_rawData);
  86.     digitalWrite(display_ILI9488_TFT_DC_PIN_D3, display_ILI9488_TFT_DC_PIN_D3_rawData);
  87. }
  88.  
  89. /****** FUNCTION TO DISPLAY CLOCK *****/
  90. void displayClock()
  91. {
  92.     // Get current time
  93.     unsigned long currentMillis = millis(); // Get the current time in milliseconds
  94.     int seconds = (currentMillis / 1000) % 60; // Calculate seconds
  95.     int minutes = (currentMillis / (1000 * 60)) % 60; // Calculate minutes
  96.     int hours = (currentMillis / (1000 * 60 * 60)) % 24; // Calculate hours
  97.  
  98.     // Prepare the time string
  99.     char timeString[9]; // HH:MM:SS
  100.     sprintf(timeString, "%02d:%02d:%02d", hours, minutes, seconds);
  101.  
  102.     // Display the time on the screen
  103.     display.setCursor(10, 50); // Set cursor position
  104.     display.setTextColor(ILI9488_WHITE); // Set text color to white
  105.     display.setTextSize(2); // Set text size
  106.     display.print(timeString); // Print the time string
  107. }
  108.  
  109. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement