Advertisement
pleasedontcode

"Display Voltage" rev_02

Jan 11th, 2025
216
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: "Display Voltage"
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2025-01-11 11:11:26
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Misura tensione da 0V a 15Vcc con st7735 */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* Measure voltage from 0V to 15V using the ST7789 */
  23.     /* display for visual output. Ensure accurate */
  24.     /* readings and display updates in real-time. Utilize */
  25.     /* appropriate libraries for ST7789 integration and */
  26.     /* voltage measurement. */
  27. /****** END SYSTEM REQUIREMENTS *****/
  28.  
  29. /* START CODE */
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <ST7789.h> // Include the ST7789 library for display
  33. #include <ADC.h>    // Include the ADC library for voltage measurement
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38.  
  39. // Create instances of the libraries
  40. ST7789 display = ST7789(); // Create an instance of the ST7789 display
  41. ADC adc = ADC();           // Create an instance of the ADC for voltage measurement
  42.  
  43. void setup(void)
  44. {
  45.     // Initialize the display
  46.     display.init();
  47.     display.setRotation(1); // Set the rotation of the display
  48.     display.fillScreen(ST77XX_BLACK); // Clear the screen with black color
  49.  
  50.     // Initialize the ADC
  51.     adc.begin(); // Start the ADC
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // Measure the voltage
  57.     float voltage = adc.readVoltage(); // Read voltage from the ADC
  58.  
  59.     // Display the voltage on the ST7789 display
  60.     display.setCursor(10, 10); // Set cursor position
  61.     display.setTextColor(ST77XX_WHITE); // Set text color to white
  62.     display.setTextSize(2); // Set text size
  63.     display.print("Voltage: ");
  64.     display.print(voltage); // Print the measured voltage
  65.     display.print(" V");
  66.  
  67.     delay(1000); // Update every second
  68. }
  69.  
  70. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement