How to make Arduino runs continuous routines even inside a "switch case loop".

PeterH:
Rather than trying to code your functions so they run 'continuously', design them so that they are called repeatedly.

Have some global variables which tell you which function(s) you should be calling. In loop(), put your code to read the input commands and update the variables to show which functions are supposed to be being called. Also in loop(), test the value of those variables to decide which function(s) need to be called, and then call them. The code will be similar to your original code, but separate out the 'reading from the serial port' from 'deciding which function to call'.

In other words, don't do this:

void loop(){

if(Serial.available()){
    delay(100);
    char ch=Serial.read();
    switch(ch)
    {
      case '1':
      SHT1();
      break;
      ... etc




Do this:



char ch = 0;
void loop(){
  if(Serial.available())
  {
    ch=Serial.read();
  }
  switch(ch)
  {
    case '1':
      SHT1();
      break;
      ... etc

Hi PeterH,
thank you for your reply! I've changed my code as suggested by you, but nothing changes in the results: every routines has been executed one time only. Is there anything else that needs to be changed in the code?
Thank you. Best wishes.