Advertisement
pleasedontcode

**Random Speed** rev_01

Apr 19th, 2025
133
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: **Random Speed**
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2025-04-19 21:46:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Utilize the Adafruit_GFX library to create a */
  21.     /* dynamic graphical display that updates based on */
  22.     /* user input, enhancing interactivity and visual */
  23.     /* feedback in the project. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* Utilize the Adafruit_GFX library to develop an */
  26.     /* interactive graphical display that responds to */
  27.     /* user inputs, providing real-time visual feedback */
  28.     /* and enhancing user experience with dynamic content */
  29.     /* updates. */
  30. /****** END SYSTEM REQUIREMENTS *****/
  31.  
  32. /* START CODE */
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <Adafruit_GFX.h>   //https://github.com/adafruit/Adafruit-GFX-Library
  36. #include <Adafruit_TFTLCD.h> // Include the TFT LCD library (assumed needed for tft instance)
  37.  
  38. // Define the pins for the TFT LCD  
  39. #define TFT_CS     10  
  40. #define TFT_RST    9  
  41. #define TFT_DC     8
  42.  
  43. // Create an instance of the TFT LCD  
  44. Adafruit_TFTLCD tft(TFT_CS, TFT_DC, TFT_RST); // Create an instance of the TFT LCD
  45.  
  46. // Speed variable  
  47. int speed = 0; // Speed in km/h (initialized to 0)
  48.  
  49. // Function to display speed on the TFT
  50. void displaySpeed(int speed) {
  51.     // Clear the previous speed display  
  52.     tft.fillRect(0, 0, 240, 40); // Clear the area for speed display
  53.  
  54.     // Display the speed  
  55.     tft.setCursor(10, 10);
  56.     tft.print("Speed: ");
  57.     tft.print(speed);
  58.     tft.print(" km/h");
  59. }
  60.  
  61. void setup(void)
  62. {
  63.     // put your setup code here, to run once:
  64.     tft.begin(); // Initialize the TFT  
  65.     tft.setRotation(1); // Set the rotation of the screen  
  66.     tft.fillScreen(WHITE); // Fill the screen with white
  67.  
  68.     // Set text properties  
  69.     tft.setTextColor(BLACK);
  70.     tft.setTextSize(3);
  71. }
  72.  
  73. void loop(void)
  74. {
  75.     // put your main code here, to run repeatedly:
  76.     // Simulate speed changes (for testing purposes)
  77.     speed = random(0, 200); // Random speed between 0 and 200 km/h
  78.  
  79.     // Call function to display the updated speed
  80.     displaySpeed(speed);
  81.  
  82.     delay(1000); // Update every second  
  83. }
  84.  
  85. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement