---

← разместить еще код

Расшаренный код:

#include <LiquidCrystal_I2C.h>
#define VoltageInput1 = 0;
#define VoltageInput2 = 1;
#define VoltageInput3 = 2;
#define TotalVoltageInput = 3;

float vout = 0;
float vin = 0;
float R1 = 100000;
float R2 = 10000;
int value = 0;
int x = 2;

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup(){
  pinMode(VoltageInput1, INPUT);
  pinMode(VoltageInput2, INPUT);
  pinMode(VoltageInput3, INPUT);
  pinMode(TotalVoltageInput, INPUT);
  lcd.init();
  lcd.backlight();
  lcd.print("VOLTAGE:");
}

void loop(){
  if (x == 1) {
    value = analogRead(TotalVoltageInput);
    vout = (value * 5.0) / 1024.0;
    vin = vout / (R2/(R1+R2)); 
    lcd.setCursor(0, 0);
    lcd.print("General: 14.8V");
    lcd.setCursor(0, 1);
    lcd.print("Current:");
    lcd.setCursor(9, 1);
    lcd.print(vin);
    lcd.setCursor(13, 1);
    lcd.print("V");
    delay(500);
  }
  if (x == 2) {
    value = analogRead(VoltageInput1);
    vout = (value * 5.0) / 1024.0;
    vin = vout / (R2/(R1+R2)); 
    lcd.setCursor(0, 1);
    lcd.print(vin);
    value = analogRead(VoltageInput2);
    vout = (value * 5) / 1024.0;
    vin = vout / (R2/(R1+R2)); 
    lcd.setCursor(5, 1);
    lcd.print(vin);
    value = analogRead(VoltageInput3);
    vout = (value * 5) / 1024.0;
    vin = vout / (R2/(R1+R2)); 
    lcd.setCursor(10, 1);
    lcd.print(vin);
    delay(500);
  }
}