Hi,
I am preparing a GPS tracker in which fetching data from Neo6MV2 and sending it to remote server using SIM900A.
In the process, there are some 5 to 8 AT commands that are related to SIM900A. The functionality is working perfect. As of now I am using delay() with it but now I want to make it with the help of millis().
So my goal is to run multiple commands one after another with the delay of 1 second.
E.g.
command1 -> command2 -> command3 -> command1 -> command2 -> command3 ......
So I created a sample code that runs 2 commands,
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
const long interval = 1000;
boolean here = false;
boolean here2 = false;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println("..................................");
unsigned long currentMillis1 = millis();
if(here == false && (currentMillis1 - previousMillis1 >= interval))
{
previousMillis1 = currentMillis1;
Serial.println("Here");
here = true;
here2 = true;
}
unsigned long currentMillis2 = millis();
if(here2 = true && (currentMillis2 - previousMillis2 >= 2000))
{
previousMillis2 = currentMillis2;
previousMillis1 = currentMillis2;
Serial.println("Here2");
here2 = false;
here = false;
}
}
But how can I make it more simpler ? In above code, no. of commands = no. of boolean flags.
After running every command, I have to disable its corresponding flag and enable the one for next one. How to make this easy ?