Advertisement
pleasedontcode

**Time Display** rev_01

Dec 9th, 2024
64
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: **Time Display**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-09 11:04:14
  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();
  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_SPI_PIN_DC_D3, display_ILI9488_TFT_SPI_PIN_RST_D2);
  57. U8G2_FOR_ADAFRUIT_GFX u8g2;
  58.  
  59. void setup(void)
  60. {
  61.     // put your setup code here, to run once:
  62.  
  63.     pinMode(display_ILI9488_TFT_RST_PIN_D2,  OUTPUT);
  64.     pinMode(display_ILI9488_TFT_DC_PIN_D3,   OUTPUT);
  65.     pinMode(display_ILI9488_TFT_SPI_PIN_CS_D10,  OUTPUT);
  66.    
  67.     // start the SPI library:
  68.     SPI.begin();
  69.  
  70.     // Initialize the display
  71.     display.begin();
  72.     u8g2.begin(display);
  73.     u8g2.setFont(u8g2_font_ncenB08_tr); // Set a font for the display
  74. }
  75.  
  76. void loop(void)
  77. {
  78.     // put your main code here, to run repeatedly:
  79.     updateOutputs(); // Refresh output data
  80.     displayClock();   // Display the clock
  81. }
  82.  
  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. void displayClock()
  90. {
  91.     // Get current time
  92.     unsigned long currentMillis = millis();
  93.     int seconds = (currentMillis / 1000) % 60;
  94.     int minutes = (currentMillis / (1000 * 60)) % 60;
  95.     int hours = (currentMillis / (1000 * 60 * 60)) % 24;
  96.  
  97.     // Clear the display
  98.     u8g2.clearBuffer();
  99.  
  100.     // Print the time on the display
  101.     u8g2.setCursor(0, 10); // Set cursor position
  102.     u8g2.print("Time: ");
  103.     u8g2.print(hours);
  104.     u8g2.print(":");
  105.     if (minutes < 10) u8g2.print("0"); // Leading zero for minutes
  106.     u8g2.print(minutes);
  107.     u8g2.print(":");
  108.     if (seconds < 10) u8g2.print("0"); // Leading zero for seconds
  109.     u8g2.print(seconds);
  110.  
  111.     // Send the buffer to the display
  112.     u8g2.sendBuffer();
  113. }
  114.  
  115. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement