This is a question about programming. Mainly about the loop() function
As an example Consider code where you get data from an accelerometer, and if the Gs are high enough you do something.
Consider the following pseudocode:
void setup()
{
pinMode(1, INPUT);
bool flag = false;
}
void loop
{
int x= analogRead(1);
if (x>2) //if the Gs we get from accelerometer
flag = true;
if (button) // if user hits the emergency button
flag = true;
if (flag == true)
{
//GET SERIAL DATA (EG GPS COORDINATES)
//DO SOME HEAVY PROCESSING
}
}
Now loop runs repeatedly That means all the commands are executed in a continuous/serial style
Since that happens, what will happen if the accelerometer reading where (x>2), which is what we look for, happen in the REAL world, at a time where in the CPU, the cpu is at that time processing or checking following commands in the program flow, like
if (button) // if user hits the emergency button
flag = true;
if (flag == true)
{
//GET SERIAL DATA (EG GPS COORDINATES)
//DO SOME HEAVY PROCESSING
}
}
Is there any chance that the cpu will miss real world events, because at that time the real world event occured, the cpu was processing other code. Or rather, not checking for that at that time. For our example, when the event occured, it wasnt checking the analogread() at that time, but was processing following code.
Should i worry about that?