need help implementing "delay" function


hi all, i've been working on (my first) project while , thought had worked out on work bench, low , behold when assembled there few hiccups  :smiley-confuse: fyi newbie here, limited knowledge/experience

so, i've commented out of "additional" features , trying basic functions working , adding in things 1 @ time until works should.

the project automated chicken coop main function door operation, motor spins pulley raises or lowers door depending on light level indicated photo resistor (open when light out, closed when dark out). motor stopped opening or closing using reed switches. currently, door function working should, i've been trying implement line of code delay motor stopping on door close routine second or after reed switch indicates door has closed. because design of door such there locking mechanism activated when there sufficient slack in line lifts door. closest (i think) i've been correct piece of code did not continue run motor after door had closed, did seem (perhaps coincidentally) prevent top (door open) switch reading correctly door open past "open" stop limit , bind up. tried replacing top switch components thinking might faulty, no avail.

i have attached full code post, section i'm working on this...

code: [select]
// stop coop door motor
void stopcoopdoormotorb() {
  digitalwrite (directionclosecoopdoormotorb, low);      // turn off motor close direction
  digitalwrite (directionopencoopdoormotorb, low);       // turn on motor open direction
  analogwrite (enablecoopdoormotorb, 0);                 // enable motor, 0 speed
}



// close coop door motor (motor dir close = clockwise)
void closecoopdoormotorb() {
  digitalwrite (directionclosecoopdoormotorb, high);     // turn on motor close direction
  digitalwrite (directionopencoopdoormotorb, low);       // turn off motor open direction
  analogwrite (enablecoopdoormotorb, 255);               // enable motor, full speed
  if (bottomswitchpinval == 0) {                         // if bottom reed switch circuit closed
//     if ((unsigned long)(millis() - coopdoormotorstop) > coopdoormotorstopdelay) {    // run motor 1 second after door closes set lock
 //     coopdoormotorstop = millis();
    stopcoopdoormotorb();
    if (serialdisplay) {
      serial.println(" coop door closed - no danger");
    }
  }
}


my attempt @ delaying motor stopping commented out line
code: [select]
//     if ((unsigned long)(millis() - coopdoormotorstop) > coopdoormotorstopdelay) {    // run motor 1 second after door closes set lock
 //     coopdoormotorstop = millis();


i have defined variables coopdoormotorstop , delay @ beginning of code follows;
code: [select]
// coop door motor delay on close
unsigned long coopdoormotorstop = 0;
unsigned long coopdoormotorstopdelay = 1000;    // run motor 1 sec after door closed set lock


i can't figure out why not delay motor stopping or why prevents top reed switch reading correctly. if can enlighten me, appreciate it.

thanks,
joe

any major objection using:

code: [select]

delay (1000);


?

i don't recommend putting delays in, blocking, occasional use, can that.


Arduino Forum > Using Arduino > Programming Questions > need help implementing "delay" function


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'