Hi everybody,
After some research inside this forum and google, I've a lot of doubt about Time management with Arduino, so I've decide to ask you some help. The goal is to create a switch case loop inside "void loop()" that execute a certain subroutine for a certain time (for example 3 minutes). The pseudocode I've thought is:
void setup() {
Serial.begin(9600);
Serial.println("Waiting for command");
}
void loop() {
// this is where the "polling" occurs
if(Serial.available()){
char ch=Serial.read();
switch(ch)
{
case '1':
// do something
break;
case '2':
//do something
break;
case '3':
void Tempfunct();
break;
default:
Serial.print(ch);
Serial.println(" : unknown command!");
}
}
}
// function to be called
void Tempfunct() {
//do something for 3*60*60*1000 s and return to switch case selection
}
I consider this solution a starting point, because I think a solution involving interrupts would be a better solution. Specifically I expect something like this pseudocode:
void setup() {
Serial.begin(9600);
Serial.println("Waiting for command");
}
void loop() {
// this is where the "polling" occurs
if(Serial.available()){
char ch=Serial.read();
switch(ch)
{
case '1':
// do something
break;
case '2':
//do something
break;
case '3':
void Tempfunct();
break;
default:
Serial.print(ch);
Serial.println(" : unknown command!");
}
}
}
// function to be called
void Tempfunct() {
//do something until an interrupt condition is received from Serial (such a key pressed by user) and then return to switch case selection
}
Can someone help me?
Thank you all!