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: **Time Display**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-09 11:04:14
- ********* 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();
- /***** 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_SPI_PIN_DC_D3, display_ILI9488_TFT_SPI_PIN_RST_D2);
- U8G2_FOR_ADAFRUIT_GFX u8g2;
- 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();
- u8g2.begin(display);
- u8g2.setFont(u8g2_font_ncenB08_tr); // Set a font for the display
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- displayClock(); // Display the clock
- }
- 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);
- }
- void displayClock()
- {
- // Get current time
- unsigned long currentMillis = millis();
- int seconds = (currentMillis / 1000) % 60;
- int minutes = (currentMillis / (1000 * 60)) % 60;
- int hours = (currentMillis / (1000 * 60 * 60)) % 24;
- // Clear the display
- u8g2.clearBuffer();
- // Print the time on the display
- u8g2.setCursor(0, 10); // Set cursor position
- u8g2.print("Time: ");
- u8g2.print(hours);
- u8g2.print(":");
- if (minutes < 10) u8g2.print("0"); // Leading zero for minutes
- u8g2.print(minutes);
- u8g2.print(":");
- if (seconds < 10) u8g2.print("0"); // Leading zero for seconds
- u8g2.print(seconds);
- // Send the buffer to the display
- u8g2.sendBuffer();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement