const int potPin = A0;
int potValue = 0; 
boolean outputPotValues = false; 
unsigned long previousMillis = 0; 
const long interval = 500;

void setup() {
  Serial.begin(9600); 
}

void loop() {

  unsigned long currentMillis = millis(); // Поточний час

  if (currentMillis - previousMillis >= interval) {
    if (Serial.available() > 0) {
      char command = Serial.read(); 
      if (command == '1') {
        outputPotValues = true;
      } else if (command == '2') {
        outputPotValues = false;
        potValue = analogRead(potPin);
        float voltage = potValue * (5.0 / 1023.0);
        Serial.print("Potentiometer Value: ");
        Serial.print(potValue);
        Serial.print(", Voltage: ");
        Serial.print(voltage);
        Serial.println(" V");
      }
    }
     if (outputPotValues) {
    potValue = analogRead(potPin);
    float voltage = potValue * (5.0 / 1023.0);
    Serial.print("Potentiometer Value: ");
    Serial.print(potValue);
    Serial.print(", Voltage: ");
    Serial.print(voltage);
    Serial.println(" V");
  }
    previousMillis = currentMillis;
  }
}