interrupting a task while it is in prosess. even if its using a delay


ok dont have code explain want, simple here go;

i have 4 buttons, , 3x3 led display witch uses 9 pins. total 13 pins buttons.
the task make 4 lightshows, , can swich between each lightshow pressing button. can swich between lightshows, means have run "test" after every delay, , use several short delays test in between each of them instead of long delay.
no matter how it, lightshow wont swich before current lightshow compleated. want able interrupt lightshow, , start one. if posible, not having hold button @ least 100ms witch not much.

i have attempted use nointerrupts , interrupts, dont how works. made total mess.
tried use break; cant use cause have use if inside while statement, , cant break while statement if.

here code, not compleated. got far. nothing set up.

code: [select]
int a=0;
int test()
{

  if (digitalread(btn[0]) == high)
  {
    = 1;
  }

  if (digitalread(btn[1]) == high)
  {
    = 2;
  }

  if (digitalread(btn[2]) == high)
  {
    = 3;
  }

  if (digitalread(btn[3]) == high)
  {
    = 4;
  }
  delay(100);
}

int ledreset()
{
  (int n = 0; n <= 8; n++)
  {
    digitalwrite(led[n], low);
  }
}


// ** * ****** * **



/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/


void loop(){
  test();

  while(a == 1)
  {
    digitalwrite(led[0], high);
    test();
    digitalwrite(led[0], low);
    test();

  }
  while(a == 2)
  {
    digitalwrite(led[1], high);
    test();
    digitalwrite(led[1], low);
    test();

  }
  while(a == 3)
  {
    digitalwrite(led[2], high);
    test();
    digitalwrite(led[2], low);
    test();

  }
  while(a == 4)
  {
    digitalwrite(led[3], high);
    test();
    digitalwrite(led[3], low);
    test();

  }
}



you might want notice how use "test();"


does have tips do? if use advanced code, please explain it.

thank guys lot.

look @ blinkwithoutdelay example in ide.

it notes time action started reading value millis() checks each time through loop() see whether required time period has elapsed.  if stops action.  if not goes round again , other things such reading input , reacting it, perhaps setting variable that, when checked, terminates current action.

reading on state machines helpful program in 1 of several states @ 1 time.  using millis() timing  state machine match, use of switch/case based on current state.

i sure realise code posted not compile.


Arduino Forum > Using Arduino > Programming Questions > interrupting a task while it is in prosess. even if its using a delay


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support