Advertisement
pleasedontcode

**Voltage Display** rev_01

Jan 11th, 2025
73
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: **Voltage Display**
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2025-01-11 10:23:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Misura tensione da 0V a 15Vcc con st7735 */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Adafruit_GFX.h>
  27. #include <Adafruit_ST7735.h>
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. // Pin definitions for the ST7735 display
  34. #define TFT_CS     10
  35. #define TFT_RST    9
  36. #define TFT_DC     8
  37.  
  38. // Create an instance of the ST7735 display
  39. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
  40.  
  41. // Function to measure voltage
  42. float measureVoltage(int pin) {
  43.     int sensorValue = analogRead(pin); // Read the analog input
  44.     float voltage = sensorValue * (15.0 / 1023.0); // Convert to voltage (0-15V)
  45.     return voltage;
  46. }
  47.  
  48. void setup(void) {
  49.     // Initialize the display
  50.     tft.initR(INITR_BLACKTAB);
  51.     tft.fillScreen(ST7735_BLACK);
  52.     tft.setTextColor(ST7735_WHITE);
  53.     tft.setTextSize(1);
  54.     tft.setCursor(0, 0);
  55.     tft.println("Voltage Measurement:");
  56. }
  57.  
  58. void loop(void) {
  59.     // Measure voltage from analog pin A0
  60.     float voltage = measureVoltage(A0);
  61.    
  62.     // Display the voltage on the screen
  63.     tft.setCursor(0, 10);
  64.     tft.fillRect(0, 10, 128, 10, ST7735_BLACK); // Clear previous voltage
  65.     tft.print("Voltage: ");
  66.     tft.print(voltage);
  67.     tft.println(" V");
  68.  
  69.     delay(1000); // Update every second
  70. }
  71.  
  72. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement