Custom Millis() delay


i have robot created needs switch autonomous mode motion control.  problem right during autonomous mode there many delays , misses character.   so have attempted  create custom timer.   right simple timer turn led on after 2 seconds if button not pushed.  though seems turn instantly when button not pushed.  led doesn't come on if button.  ideas?

code: [select]
unsigned long timer;

void setup()
{
  serial.begin(9600);// put setup code here, run once:
  pinmode(13, output);
  pinmode(7, input);
  digitalwrite(7, high);
}
  void loop()
{
  int button = digitalread(7);
  if(button == 1)
  {
    digitalwrite(13, high);
    timer = millis();
      if (( timer - millis()) >= 15000)
     {
      digitalwrite(13, low);
     }
  }// put main code here, run repeatedly:
 
}

what make pin go low? external pulldown resistor?
assuming have one, tiime test never true:

timer = millis();
      if (( timer - millis()) >= 15000)

timer- millis() never more 1 2 instructions mere microseconds apart.
need revise logic.

also, can go before setup:
int button = digitalread(7);
no need declare every pass thru loop; can just  byte vs int.


Arduino Forum > Using Arduino > Programming Questions > Custom Millis() 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