time consuming function, how to get back to void loop?


i making program involves input(sensor), servo, , feedback(sensor).
also used interrupts codes

i have 2 questions:
1. in void loop, need finish function called inside in order restart loop?
2. if q1 true, can go start of loop while program @ called function.

here sample code understand:

code: [select]
void setup()
{
  attachinterrupt(0, rty, falling);   //interrupt input
  attachinterrupt(1, uio, falling);   //interrupt feedback
}

void loop()
{
  // here involves millis() 
   (if else statement)
   {
      abc();   //function1 called
    }
  // increment/transfer values.
    (if else statement)
    {
        def(); //function2 called time consuming 4-7secs.
    }
}

void abc()
{
  //do something
}

//interrupt input
void rty()
{
  count1++;
  recordtime= millis();
}

//interrupt feedback
void uio()
{
  count2++;
}

void def()
{
  //do time consuming.
}

you have 1 processor , no threads or os level processus (there no os) function indeed needs return before loop can continue, ends , start again

you need study state machines call repetitively function loop until completes - , ensure function proceeds small steps small steps not lockup loop if care catching events main loop

(ensure count variables defined volatile)


Arduino Forum > Using Arduino > Programming Questions > time consuming function, how to get back to void loop?


arduino

Comments

Popular posts from this blog

Help with codes to add 1 more shift register and add more to matrix LED

tcp client

Can't read sms using Thinker A7 communicate with Arduino