help analog input with button

what program should be added if I want when analog input A0 and analog input A1 have the same value in 1023 and enable the digital pin 11 to HIGH.
The following program I have created:

int sensorZona1 = A0;
int sensorZona2 = A1;
int sensorValue = 0;
int ledZona1 = 13;
int ledZona2 = 12;
int ledZona1and2 = 11;

void setup()
{
  pinMode(sensorZona1, INPUT);
  pinMode(sensorZona2, INPUT);
  pinMode(ledZona1, OUTPUT);
  pinMode(ledZona2, OUTPUT);
  pinMode(ledZona1and2, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  //memanggil fungsi zona1
  zona1();
  //memanggil fungsi zona2
  zona2();
}

void zona1()
{
  sensorValue = analogRead(sensorZona1);
  if (sensorValue > 1022)
  {
  digitalWrite (ledZona1, HIGH);
  Serial.print("sensor Zona 1 ");
  Serial. println(sensorValue);
  }
  else
  {
    digitalWrite (ledZona1, LOW);
    Serial.print("sensor Zona 1 ");
    Serial. println(sensorValue);
  }
  delay(1000);
}

void zona2()
{
  sensorValue = analogRead(sensorZona2);
  if (sensorValue > 1022)
  {
  digitalWrite (ledZona2, HIGH);
  Serial.print("sensor Zona 2 ");
  Serial. println(sensorValue);
  }
  else
  {
    digitalWrite (ledZona2, LOW);
    Serial.print("sensor Zona 2 ");
    Serial. println(sensorValue);
  }
  delay(1000);
}

Thank you for attention :slight_smile:

untested:

int sensorZona1 = A0;
int sensorZona2 = A1;
int sensorValue = 0;
int ledZona1 = 13;
int ledZona2 = 12;
int ledZona1and2 = 11;

void setup()
{
  pinMode(sensorZona1, INPUT);
  pinMode(sensorZona2, INPUT);
  pinMode(ledZona1, OUTPUT);
  pinMode(ledZona2, OUTPUT);
  pinMode(ledZona1and2, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  //memanggil fungsi zona1
  bool firstZone = zona1();
  //memanggil fungsi zona2
  bool secondZone = zona2();
  if (firstZone == true && secondZone == true)// 
  {
    digitalWrite(ledZona1and2, HIGH);
  }
  else
  {
    digitalWrite(ledZona1and2, LOW);
  }
  delay(1000);
}

bool zona1()
{
  sensorValue = analogRead(sensorZona1);
  if (sensorValue > 1022)
  {
  digitalWrite (ledZona1, HIGH);
  Serial.print("sensor Zona 1 ");
  Serial. println(sensorValue);
  }
  else
  {
    digitalWrite (ledZona1, LOW);
    Serial.print("sensor Zona 1 ");
    Serial. println(sensorValue);
  }
  //delay(1000);
  if (sensorValue == 1023)
  {
    return true;
  }
  else
  {
    return false;
  }
}

bool zona2()
{
  sensorValue = analogRead(sensorZona2);
  if (sensorValue > 1022)
  {
  digitalWrite (ledZona2, HIGH);
  Serial.print("sensor Zona 2 ");
  Serial. println(sensorValue);
  }
  else
  {
    digitalWrite (ledZona2, LOW);
    Serial.print("sensor Zona 2 ");
    Serial. println(sensorValue);
  }
  //delay(1000);
  if (sensorValue == 1023)
  {
    return true;
  }
  else
  {
    return false;
  }
}
int sens1
int sens2


void doSensors(){
sens1=analogRead(sensor1);
sens2=analogRead(sensor2); 
}

void doOutput(){
if (sens1>1022) {

} else {

}
if (sens2>1022) {
//if second sensor is 1023
} else {
//if it's not
}
if ((sens1>1022) && (sens2>1022)) {
 //code to run when both read 1023
}
}

void loop() {
doSensors();
doOutput();
delay(1000); //I wouldn't use delay; you only need it to control serial spam.
}

This is how I'd approach that - fill in the code in the if/else, and take a look at what I'm doing. I separated the reading of the sensors from the reacting to what they've read, and I store the values. Often when taking analogRead() values, you do a few samples and average them to improve accuracy - here that doesn't make sense, since you're only looking for the very high end of the range, but most of the time it does.

You'll probably need to lower the threshold a bit - I've seen the ADC give values that are like 1020-1022 when I'd expect it to be 1023.

hello sir thank you for attention..

I've tried what you suggest, but there is no result, which I can when using a program that you recommend is output LED could light when the pin 13 when I press a button pin A0,, but on output led pin 12 does not turn on when I press the button pin A1..