<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 03/09/2018 08:37 AM, Alex Davis via
      TriEmbed wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:19219EB2-A169-483B-B280-200EDCE14E9A@matrixwide.com">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      Following on my sleep/wake issues with the Feather M0, I have
      switched to the Feather 32u4. The 32u4 is less flexible with
      regards to external pin change interrupts, so I have kept things
      simple and just went with hardware interrupts INT2 and INT3.
      <div class=""><br class="">
      </div>
      <div class="">I’m using <avr/sleep.h> and have no trouble
        waking the micro on external interrupt.</div>
      <div class=""><br class="">
      </div>
      <div class="">The problem comes with polling the input used for
        the interrupt to detect button presses. I would like to wake on
        pin LOW (button tied to ground) and then time how long the
        button is pressed down. This way accidental button presses will
        be less likely to turn the device on.</div>
      <div class=""><br class="">
      </div>
      <div class="">The code looks like this - simplified with LEDs to
        show what it is doing vs my actual code:</div>
      <div class=""><br class="">
      </div>
      <div class="">
        <div class="">  // red LED on until button is pressed</div>
        <div class="">  digitalWrite(RED_LED, HIGH);</div>
        <div class=""><br class="">
        </div>
        <div class="">  // spin around until the button is pressed</div>
        <div class="">  while (digitalRead(BUTTON_0) == HIGH);</div>
        <div class=""><br class="">
        </div>
        <div class="">  // red LED off</div>
        <div class="">  digitalWrite(RED_LED, LOW);</div>
        <div class="">  // blue LED on</div>
        <div class="">  digitalWrite(BLUE_LED, HIGH);</div>
        <div class="">  </div>
        <div class="">  // wait a bit to settle bouncing</div>
        <div class="">  delay(50);</div>
        <div class="">  // start button timer</div>
        <div class="">  buttonTime = (unsigned long)millis();  </div>
        <div class="">  // see if the button is held down long enough</div>
        <div class="">  while (digitalRead(BUTTON_0) == LOW)</div>
        <div class="">  {</div>
        <div class="">    // if the button is held down LONG_CLICK_MS or
          more</div>
        <div class="">    if (((unsigned long)millis() - buttonTime)
          > LONG_CLICK_MS)</div>
        <div class="">    {</div>
        <div class="">      digitalWrite(BLUE_LED, LOW);</div>
        <div class="">    }</div>
        <div class="">  }</div>
        <div class="">  digitalWrite(RED_LED, HIGH);</div>
        <div class=""><br class="">
        </div>
        <div class="">This works as expected when it has not woke from
          an interrupt on BUTTON_0 (INT2). However, if I wake from INT2
          (detaching it as soon as I wake) and run it, it will spin
          around forever in the second while loop until the button is
          released. It is </div>
      </div>
    </blockquote>
    Despite having detached the INT2 interrupt, are you still inside the
    handler for that interrupt when you enter the code dependent on
    millis()? If you're in an interrupt handler, millis() cannot work,
    because it's dependent on an interrupt that you are holding off
    forever.<br>
    -Pete<br>
    <blockquote type="cite"
      cite="mid:19219EB2-A169-483B-B280-200EDCE14E9A@matrixwide.com">
      <div class="">
        <div class="">as though Arduino pin 0 (PD2/INT2) being high
          somehow breaks millis(). It is not a case of millis() alone
          being broken after waking, as I can use it as a delay loop
          right after waking with no issue. I just can not combine it
          with polling the PD3 pin.</div>
        <div class=""><br class="">
        </div>
        <div class="">My work around for the time being is to wake on
          INT2 (pin 0 or PD2) and then look for a long press on pin 1 or
          PD3. It requires me to have the second button, though.</div>
        <div class=""><br class="">
        </div>
        <div class="">Interestingly enough, the exact same
          <avr/sleep.h> code and millis() loop wake/long button
          press detect routine works fine on an ATTINY85 (as used in my
          UV meter business card).</div>
        <div class=""><br class="">
        </div>
        <div class="">I NEED TO BUY A DEBUGGER!!!</div>
        <div class="">
          <div style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class=""><br class="Apple-interchange-newline">
            |\ |  (¯  \/ |¯\  |V| |\ ¯|¯ |¯) | \/ | | | |¯\ (¯   /¯  /\
            |V|</div>
          <div style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class="">|-||_ (_  /\ |_/ @| | |-| |  | \ | /\ |^| |
            |_/ (_ . \_  \/ | |</div>
          <br style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class="">
          <br style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class="">
          <br style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class="">
          <br style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class="">
          <br style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class="">
          <br style="color: rgb(0, 0, 0); font-family: Monaco;
            font-style: normal; font-variant-caps: normal; font-weight:
            normal; letter-spacing: normal; orphans: 2; text-align:
            start; text-indent: 0px; text-transform: none; white-space:
            normal; widows: 2; word-spacing: 0px;
            -webkit-text-size-adjust: auto; -webkit-text-stroke-width:
            0px;" class="">
        </div>
        <br class="">
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Triangle, NC Embedded Computing mailing list

To post message: <a class="moz-txt-link-abbreviated" href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a>
List info: <a class="moz-txt-link-freetext" href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a>
TriEmbed web site: <a class="moz-txt-link-freetext" href="http://TriEmbed.org">http://TriEmbed.org</a>
To unsubscribe, click link and send a blank message: <a class="moz-txt-link-freetext" href="mailto:unsubscribe-TriEmbed@bitser.net?subject=unsubscribe">mailto:unsubscribe-TriEmbed@bitser.net?subject=unsubscribe</a>

</pre>
    </blockquote>
    <br>
  </body>
</html>