user35016: This is my Arduino code that checks the water Level of two different water reservoirs via 2 water Level Sensors A and B:
#define Water_Level_A 5;
#define Water_Level_B 6;

boolean Water_Level_Check_A(){
boolean Result = digitalRead(Water_Level_A);
return Result;
}
boolean Water_Level_Check_B(){
boolean Result = digitalRead(Water_Level_B);
return Result;
}

void setup() {
    Serial.begin(9600);
    pinMode(Water_Level_A,INPUT);
    pinMode(Water_Level_B,INPUT);
    }

void loop() {
if (Water_Level_Check_A() == LOW){
--> Water Pump A
}
if Water_Level_Check_B() == LOW{
--> Water Pump B
}

What's the best way to simplify this code so that I only need one Water_Level_Check function so that the distinction between A and B and Water_Level_A and Water_Level_B is made within the function and the loop part looks like this:
void loop() {
if (Water_Level_Check_(A) == LOW){
--> Water Pump A 
}
if Water_Level_Check_(B) == LOW{
--> Water Pump B
}


user313: I think what you're asking for is something like this:
boolean Water_Level_Check(uint8_t level_pin){
   boolean Result = digitalRead(pin);
   if( level_pin == Water_Level_A ){
      // manage pump A here
   }
   else if( level_pin == Water_Level_B ){
      // manage pump B here
   }
   else {
      Serial.println("Water_Level_Check: unknown pin number.");
      // or some other way of dealing with a bad-pin-number bug.
      return -1;
   }

   return Result;
}

for the level testing function, which will simplify you loop function to:
void loop() {
   (void)Water_Level_check(Water_Level_A);
   (void)Water_Level_check(Water_Level_B);
}

The (void) expression before each call is a "cast to void", telling the the compiler to consider the function's boolean return value to have been intentionally "voided", i.e. you intended not to read it, and not to give an error message.

user30175: Functions like 
boolean Water_Level_Check_A(){
   boolean Result = digitalRead(Water_Level_A);
   return Result;
}

Are really overcomplicated. You're just calling one function and returning that value, so it can be simplified to 
boolean Water_Level_Check_A(){
   return digitalRead(Water_Level_A);
}

Or just the expression 
digitalRead(Water_Level_A)

whenever you need it. 
So all you're doing is calling digitalRead() on a pin number and check if the result is low. If you really want to move this to a different function then you could give it the pin number argument and directly invert the result so that a true from this function means that some action needs to be done.
boolean Water_Level_Check(int sensorPin){
   return !digitalRead(sensorPin);
}

And then call it as 
void loop() {
   if (Water_Level_Check(Water_Level_A)){
       //--> Water Pump A
   }
   if (Water_Level_Check(Water_Level_B )){
       //--> Water Pump B
   }
}


35016: <p>This is my Arduino code that checks the water Level of two different water reservoirs via 2 water Level Sensors A and B:</p>

<pre><code>#define Water_Level_A 5;
#define Water_Level_B 6;

boolean Water_Level_Check_A(){
boolean Result = digitalRead(Water_Level_A);
return Result;
}
boolean Water_Level_Check_B(){
boolean Result = digitalRead(Water_Level_B);
return Result;
}

void setup() {
    Serial.begin(9600);
    pinMode(Water_Level_A,INPUT);
    pinMode(Water_Level_B,INPUT);
    }

void loop() {
if (Water_Level_Check_A() == LOW){
--&gt; Water Pump A
}
if Water_Level_Check_B() == LOW{
--&gt; Water Pump B
}
</code></pre>

<p>What's the best way to simplify this code so that I only need one <code>Water_Level_Check</code> function so that the distinction between A and B and Water_Level_A and Water_Level_B is made within the function and the loop part looks like this:</p>

<pre><code>void loop() {
if (Water_Level_Check_(A) == LOW){
--&gt; Water Pump A 
}
if Water_Level_Check_(B) == LOW{
--&gt; Water Pump B
}
</code></pre>
 313: <p>I think what you're asking for is something like this:</p>

<pre><code>boolean Water_Level_Check(uint8_t level_pin){
   boolean Result = digitalRead(pin);
   if( level_pin == Water_Level_A ){
      // manage pump A here
   }
   else if( level_pin == Water_Level_B ){
      // manage pump B here
   }
   else {
      Serial.println("Water_Level_Check: unknown pin number.");
      // or some other way of dealing with a bad-pin-number bug.
      return -1;
   }

   return Result;
}
</code></pre>

<p>for the level testing function, which will simplify you loop function to:</p>

<pre><code>void loop() {
   (void)Water_Level_check(Water_Level_A);
   (void)Water_Level_check(Water_Level_B);
}
</code></pre>

<p>The <code>(void)</code> expression before each call is a "cast to void", telling the the compiler to consider the function's boolean return value to have been intentionally "voided", i.e. you <em>intended</em> not to read it, and not to give an error message.</p>
 30175: <p>Functions like </p>

<pre><code>boolean Water_Level_Check_A(){
   boolean Result = digitalRead(Water_Level_A);
   return Result;
}
</code></pre>

<p>Are really overcomplicated. You're just calling one function and returning that value, so it can be simplified to </p>

<pre><code>boolean Water_Level_Check_A(){
   return digitalRead(Water_Level_A);
}
</code></pre>

<p>Or just the expression </p>

<pre><code>digitalRead(Water_Level_A)
</code></pre>

<p>whenever you need it. </p>

<p>So all you're doing is calling <code>digitalRead()</code> on a pin number and check if the result is low. If you really want to move this to a different function then you could give it the pin number argument and directly invert the result so that a <code>true</code> from this function means that some action needs to be done.</p>

<pre><code>boolean Water_Level_Check(int sensorPin){
   return !digitalRead(sensorPin);
}
</code></pre>

<p>And then call it as </p>

<pre><code>void loop() {
   if (Water_Level_Check(Water_Level_A)){
       //--&gt; Water Pump A
   }
   if (Water_Level_Check(Water_Level_B )){
       //--&gt; Water Pump B
   }
}
</code></pre>
