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: **Clock Display**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-12-09 11:30:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* print a clock on display and each number is within */
- /* a circle. */
- /****** 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 drawClock();
- /***** 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 *****/
- /***** used to store raw data *****/
- bool display_ILI9488_TFT_RST_PIN_D2_rawData = 0;
- bool display_ILI9488_TFT_DC_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- 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 display object
- ILI9488 tft(display_ILI9488_TFT_SPI_PIN_CS_D10, display_ILI9488_TFT_DC_PIN_D3, display_ILI9488_TFT_RST_PIN_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
- tft.begin();
- tft.setRotation(3); // Set rotation if needed
- tft.fillScreen(ILI9488_BLACK); // Clear screen
- u8g2.begin(tft); // Initialize U8g2 with the display
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- drawClock(); // Call function to draw clock
- delay(1000); // Update every second
- }
- void drawClock() {
- // Get current hour and minute
- int hour = hour(); // Assuming you have a function to get the current hour
- int minute = minute(); // Assuming you have a function to get the current minute
- // Clear the previous clock
- tft.fillScreen(ILI9488_BLACK);
- // Draw clock face
- int centerX = tft.width() / 2;
- int centerY = tft.height() / 2;
- int radius = 100;
- // Draw circles for each hour
- for (int i = 0; i < 12; i++) {
- float angle = (i * 30) * (PI / 180); // 30 degrees for each hour
- int x = centerX + radius * cos(angle);
- int y = centerY + radius * sin(angle);
- tft.drawCircle(x, y, 20, ILI9488_WHITE); // Draw circle for hour
- u8g2.setFont(u8g2_font_ncenB08_tr); // Set font for hour numbers
- u8g2.setCursor(x - 5, y + 5); // Position cursor
- u8g2.print(i + 1); // Print hour number
- }
- // Draw hands for the current time
- float hourAngle = (hour % 12 + minute / 60.0) * 30; // Hour hand
- float minuteAngle = minute * 6; // Minute hand
- // Draw hour hand
- int hourX = centerX + (radius - 40) * cos(hourAngle * (PI / 180));
- int hourY = centerY + (radius - 40) * sin(hourAngle * (PI / 180));
- tft.drawLine(centerX, centerY, hourX, hourY, ILI9488_WHITE);
- // Draw minute hand
- int minuteX = centerX + (radius - 20) * cos(minuteAngle * (PI / 180));
- int minuteY = centerY + (radius - 20) * sin(minuteAngle * (PI / 180));
- tft.drawLine(centerX, centerY, minuteX, minuteY, ILI9488_WHITE);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement