Hello, I was wondering if there is a way to execute something inside a switch/case every time the switch is called.
void irrigationOnPot1(int a){
switch(a){
case 1:
{
lightValue = analogRead(lightSensor);
DHT.read11(ht_sensor);
int temp = DHT.temperature;
moistureValue1 = analogRead(moistureSensor1);
if (moistureValue1 < 300){
if (temp < 7 && lightValue > 300){
for(int i = 180; i > 0; i-=1){
servo1.write(i);
delay(100);
}
}
else if (temp >= 7 && lightValue <= 300){
for(int i = 180; i > 0; i-=5){
servo1.write(i);
}
}
}
else {
servo1.write(180); //Close State.
}
}
break;
case 2:
{
lightValue = analogRead(lightSensor);
DHT.read11(ht_sensor);
int temp = DHT.temperature;
moistureValue1 = analogRead(moistureSensor1);
if (moistureValue1 < 300){
if (temp < 7 && lightValue > 300){
for(int i = 180; i > 0; i+=5){
servo1.write(i);
}
}
else if (temp <= 7 && lightValue >= 300){
for(int i = 180; i > 0; i+=5){
servo1.write(i);
}
}
}
else {
servo1.write(180); //Close State.
}
}
break;
Cases might be similar since i'm still working on it and I know there are some mistakes.
My question is, is there a way to execute something for every case without the necessity of having to add it to every case individually.
Best Regards.