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: **Voltage Display**
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2025-01-11 10:23:08
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Misura tensione da 0V a 15Vcc con st7735 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Adafruit_GFX.h>
- #include <Adafruit_ST7735.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Pin definitions for the ST7735 display
- #define TFT_CS 10
- #define TFT_RST 9
- #define TFT_DC 8
- // Create an instance of the ST7735 display
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
- // Function to measure voltage
- float measureVoltage(int pin) {
- int sensorValue = analogRead(pin); // Read the analog input
- float voltage = sensorValue * (15.0 / 1023.0); // Convert to voltage (0-15V)
- return voltage;
- }
- void setup(void) {
- // Initialize the display
- tft.initR(INITR_BLACKTAB);
- tft.fillScreen(ST7735_BLACK);
- tft.setTextColor(ST7735_WHITE);
- tft.setTextSize(1);
- tft.setCursor(0, 0);
- tft.println("Voltage Measurement:");
- }
- void loop(void) {
- // Measure voltage from analog pin A0
- float voltage = measureVoltage(A0);
- // Display the voltage on the screen
- tft.setCursor(0, 10);
- tft.fillRect(0, 10, 128, 10, ST7735_BLACK); // Clear previous voltage
- tft.print("Voltage: ");
- tft.print(voltage);
- tft.println(" V");
- delay(1000); // Update every second
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement