How to execute a function for "t" time without delay + using external interrupt

Chagrin:
Just FYI:

#include <Time.h>

#include <TimeAlarms.h>

void setup() {
 Serial.begin(9600);
 Serial.println("Waiting for command");
}

AlarmID_t temptimer;
 
void loop() {
     
 // this is where the "polling" occurs
 if(Serial.available()){
   char ch=Serial.read();
   switch(ch)
   {
     case '1':
     // start recording?
     temptimer = Alarm.timerRepeat(1, Tempfunct);
     break;
   
     case '2':
     // stop recording?
     Alarm.disable(temptimer);
     break;
         
     default:
     Serial.print(ch);
     Serial.println(" : unknown command!");
   }  
 }
}

// function to be called
void Tempfunct() {
  // do whatever reading
  Serial.println(analogRead(A0));
}




This is perhaps kinda heavy for what you appear to be doing (should use the "blink without delay" method), but just wanted to followup.

Also, TimeAlarms.cpp needs to be updated for Arduino 1.0. 

Replace:`#include <WProgram.h>`

With:

#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

Thank you for your reply. I prefer to use every case to control a method and each method to control a sensor: so I imagine to have something like:

#include <Time.h>
#include <TimeAlarms.h>

void setup() {
  Serial.begin(9600);
  Serial.println("Waiting for command");
}
 
AlarmID_t temptimer;
  
void loop() {
       
  // this is where the "polling" occurs
  if(Serial.available()){
    char ch=Serial.read();
    switch(ch)
    {
      case '1':
      // control sensor 1 
      sens1();
      break;
     
      case '2':
      // control sensor 2
      sens2();
      break;

      case'3':
      // control pressure sensor
      pressfunct(); 
      break;
     
      default:
      Serial.print(ch);
      Serial.println(" : unknown command!");
    }   
  }
}

void sens1(){
//do something;}
void sens2(){
//do something;}

// function to control pressure sensor (start/stop measurement)
void pressfunct() {
while(key==...){
//start measurement (i.e f=1 data for second);}
//measurement continue until i press another key : key2==...
//after Arduino receive key2, stop measurement and return to "void loop()", waiting for..

}