Loop delay avoiding


hi guys!
i have question, trying control stepper motor pololu stepper driver. change speed of motor +5v singals parallel port, , buttons. have made code , works, have problem delay function. loop runs non stop , everytime delay used, when speed of motor example delay of 250ms, runs 1 loop , uses normal delay of 500ms, , again 250ms. possible run 1 delay @ thime? experimenting milis() failed.


code: [select]


const int step = 5;     
const int smer =  6;
const int e = 4;
const int w = 3;

int komandae = 0;
int komandaw = 0;


   

void setup() {
  // put setup code here, run once:
pinmode(step, output);
pinmode(smer, output);
pinmode(e, input);
pinmode(w, input);


}


void loop()
{
digitalwrite(smer, low);
digitalwrite(step, low);
serial.begin(9600);
unsigned long currentmillis = millis();
   {
    digitalwrite(step,high); // output high
    delay(500); // wait
    digitalwrite(step,low); // output low
    delay(500); // wait
  }
 komandae = digitalread (e);
  if (komandae==high)
    {
      digitalwrite(step,high); // output high     <== run delay
      delay(250); // wait                                       ||
      digitalwrite(step,low); // output low       <===
      delay(250); // wait   
    }
   else
   {
    digitalwrite(step,high); // output high
    delay(500); // wait
    digitalwrite(step,low); // output low
    delay(500); // wait
  }
   }

you need remove delay() calls, have experimented.

you need understand finite state machines (fsm) in order implement type of code properly. please - there lot of information in this. allow separate command , motor running code more effectively.


Arduino Forum > Using Arduino > Programming Questions > Loop delay avoiding


arduino

Comments