Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Falesh
#55117 The following code keeps an LED on while it is running. The code below works perfectly.
Code: Select all  for(q=0;q<10;q++) {
    for(y=0;y<20;y++) {
      if(y<20) {
        /* One cycle of HIGH */
        for(x=0;x<8;x++) {
          for(i=0;i<8;i++) {
            digitalWrite(serialIn, HIGH);
            digitalWrite(srck, HIGH);
            digitalWrite(srck, LOW);
          }
          digitalWrite(latch, HIGH);
          digitalWrite(latch, LOW);
        }
      } else {
        /* One cycle of LOW */
        for(x=0;x<8;x++) {
          for(i=0;i<8;i++) {
            digitalWrite(serialIn, LOW);
            digitalWrite(srck, HIGH);
            digitalWrite(srck, LOW);
          }
          digitalWrite(latch, HIGH);
          digitalWrite(latch, LOW);
        }
      }
    }
  }


However when I change "for(q=0;q<10;q++)" to "for(q=0;q<10000;q++)" it runs fine for a few seconds and the LED on the ESP8266 flashes and the LED the code is controlling goes out for a second or two, so I guess the ESP8266 rebooted. The entire code is below.

Code: Select allint srck = 15;
int latch = 13;
int reset = 12;
int serialIn = 14;

int x = 0;
int i = 0;
int y = 0;
int z = 0;
int q = 0;

void setup() {
  pinMode(srck, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(reset, OUTPUT);
  pinMode(serialIn, OUTPUT);
 
 
  digitalWrite(srck, LOW);
  digitalWrite(latch, LOW);
  digitalWrite(reset, LOW);
  digitalWrite(serialIn, LOW); 

  digitalWrite(reset, HIGH);delay(1);
  digitalWrite(reset, LOW);delay(1);
}

void loop() {
  for(q=0;q<10000;q++) {
    for(y=0;y<20;y++) {
      if(y<20) {
        /* One cycle of HIGH */
        for(x=0;x<8;x++) {
          for(i=0;i<8;i++) {
            digitalWrite(serialIn, HIGH);
            digitalWrite(srck, HIGH);
            digitalWrite(srck, LOW);
          }
          digitalWrite(latch, HIGH);
          digitalWrite(latch, LOW);
        }
      } else {
        /* One cycle of LOW */
        for(x=0;x<8;x++) {
          for(i=0;i<8;i++) {
            digitalWrite(serialIn, LOW);
            digitalWrite(srck, HIGH);
            digitalWrite(srck, LOW);
          }
          digitalWrite(latch, HIGH);
          digitalWrite(latch, LOW);
        }
      }
    }
  }
}


Does anyone have any idea why it would be acting like this?
User avatar
By Falesh
#55166 You're right, it was the long loop, I had it in my head it was some kind of memory leak. Adding delay(0) to the outer loop stopped the resets. I checked the performance hit of adding the delay; it took 5970 nanoseconds, for context a digitalWrite takes 450 nanoseconds.

Cheers!