<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Pat,</p>
    <p>This was my earlier suspicion, which is why I asked what happened
      if you replaced the maxDistance with an explicit 200.  You said it
      had the same problem.  How can that be?</p>
    <p>just curious</p>
    <p>David</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 12/17/21 7:42 PM, Pat Caron via
      DPRGlist wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CA+mr86eDHxud21gfGXzsVAjyVv_NHoqGOo7MA8Uf7qaJ0ZV1wg@mail.gmail.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p style="background-color: #f4eaa5;color: #000000
        ;margin:5px;padding: 2px;text-align: left !important;
        align-content: center; display: block; border: 1px solid
        #000000; font-size: large; font-family: sans-serif;"><strong><em
            style="font-size: 11px;"> [EXTERNAL SENDER]</em></strong></p>
      <div dir="ltr">
        <div class="gmail_default" style="font-size:small">Thanks
          everyone for the help.  This is now working as expected.</div>
        <div class="gmail_default" style="font-size:small">maxDistance
          was being overwritten to 0 in what I thought was a disabled
          function.</div>
        <div class="gmail_default" style="font-size:small"><br>
        </div>
        <div class="gmail_default" style="font-size:small">if ((cm[x] ==
          0) or (cm[x] > maxDistance)) {<br>
                cm[x] = 999;<br>
              }</div>
        <div class="gmail_default" style="font-size:small">Output:<br>
        </div>
        <div class="gmail_default" style="font-size:small">--- Miniterm
          on /dev/ttyUSB-sensors  115200,8,N,1 ---<br>
          --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by
          Ctrl+H ---<br>
          maxDistance = 200<br>
          cm[0] = 0<br>
          cm[1] = 92<br>
          cm[2] = 91<br>
          cm[3] = 90<br>
          cm[4] = 249<br>
          | us_Left = 999cm | us_Mid = 92cm | us_Right = 91cm | ir_Left
          = 90cm | ir_Right = 999cm | Time = 46mS</div>
        <div class="gmail_default" style="font-size:small">...Pat C.<br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, Dec 17, 2021 at 8:16
          PM Pat Caron <<a href="mailto:patcaron@mail.com"
            moz-do-not-send="true">patcaron@mail.com</a>> wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div dir="ltr">
            <div class="gmail_default" style="font-size:small">I did
              another quick test removing the cm[x] == 0 condition &
              leaving the > 200 instead of maxDistance.<br>
            </div>
            <div class="gmail_default" style="font-size:small">if
              ((cm[x] > 200)) {<br>
                    cm[x] = 999;<br>
                  }<br>
            </div>
            <div class="gmail_default" style="font-size:small">This also
              worked as expected.</div>
            <div class="gmail_default" style="font-size:small">Output:</div>
            <div class="gmail_default" style="font-size:small">---
              Miniterm on /dev/ttyUSB-sensors  115200,8,N,1 ---<br>
              --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by
              Ctrl+H ---<br>
              cm[0] = 0<br>
              cm[1] = 92<br>
              cm[2] = 91<br>
              cm[3] = 90<br>
              cm[4] = 248<br>
              | us_Left = 0cm | us_Mid = 92cm | us_Right = 91cm |
              ir_Left = 90cm | ir_Right = 999cm | Time = 46mS</div>
            <div class="gmail_default" style="font-size:small"><br>
            </div>
            <div class="gmail_default" style="font-size:small">I then
              put maxDistance back in without the cm[x] == 0 and it
              failed!</div>
            <div class="gmail_default" style="font-size:small">if
              ((cm[x] > maxDistance)) {<br>
                    cm[x] = 999;<br>
                  }</div>
            <div class="gmail_default" style="font-size:small">---
              Miniterm on /dev/ttyUSB-sensors  115200,8,N,1 ---<br>
              --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by
              Ctrl+H ---<br>
              cm[0] = 0<br>
              cm[1] = 93<br>
              cm[2] = 91<br>
              cm[3] = 90<br>
              cm[4] = 250<br>
              | us_Left = 0cm | us_Mid = 999cm | us_Right = 999cm |
              ir_Left = 999cm | ir_Right = 999cm | Time = 46mS</div>
            <div class="gmail_default" style="font-size:small"><br>
            </div>
            <div class="gmail_default" style="font-size:small">...Pat C.<br>
            </div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Fri, Dec 17, 2021 at
              7:34 PM Pat Caron <<a href="mailto:patcaron@mail.com"
                target="_blank" moz-do-not-send="true">patcaron@mail.com</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div dir="ltr">
                <div class="gmail_default" style="font-size:small">So I
                  did a quick test removing the second condition</div>
                <div class="gmail_default" style="font-size:small"><br>
                </div>
                <div class="gmail_default" style="font-size:small">if
                  ((cm[x] == 0)) { // or (cm[x] > maxDistance)) {<br>
                        cm[x] = 999;<br>
                      }</div>
                <div class="gmail_default" style="font-size:small"><br>
                </div>
                <div class="gmail_default" style="font-size:small">This
                  is working!  Now I need to find out why the >
                  maxDistance condition is causing the failure.<br>
                </div>
                <div class="gmail_default" style="font-size:small">Output:</div>
                <div class="gmail_default" style="font-size:small">---
                  Miniterm on /dev/ttyUSB-sensors  115200,8,N,1 ---<br>
                  --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T
                  followed by Ctrl+H ---<br>
                  cm[0] = 0<br>
                  cm[1] = 93<br>
                  cm[2] = 91<br>
                  cm[3] = 90<br>
                  cm[4] = 252<br>
                  | us_Left = 999cm | us_Mid = 93cm | us_Right = 91cm |
                  ir_Left = 90cm | ir_Right = 252cm | Time = 46mS<br>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Fri, Dec 17, 2021
                  at 5:35 PM Rud Merriam via DPRGlist <<a
                    href="mailto:dprglist@lists.dprg.org"
                    target="_blank" moz-do-not-send="true">dprglist@lists.dprg.org</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">
                  <div>
                    <p>Okay, so we know it is happening in the handling
                      of the conditional. Run it twice. Once with the
                      test for maxDistance removed and once with the
                      test for equality removed. Also, add a print out
                      of <i>maxDistance</i>. Need to make sure it is
                      not being changed although the test with '200'
                      there should show it isn't. <br>
                    </p>
                    <p>If you get the same results I'm going to start
                      drinking. <br>
                    </p>
                    <p>Actually, I'll start wondering about the build
                      process. I'm not familiar with PlatformIO. The
                      Arduino IDE takes all the files, rearranges them,
                      and then compiles the resulting file. That's
                      unlike most C++ build systems. The "rearranging"
                      can lead to some strange issues. <br>
                    </p>
                    <div><font face="Comic Sans MS" color="#000080"> <br>
                        -73 - <br>
                        <b>Rud Merriam K5RUD</b> <br>
                        <a
href="http://secure-web.cisco.com/1L_tRh7d2I9r0OgjobcEuIU_IszpkQq_xbnOiEo1x0nbY9Kmp2qUGFRPorl51SZ-ZHIkthbQu-To2vCaw9oOiALtmhVTyFIXFLRTHcR9EkjyUtrNpHSakTKr6Uj09uzEvHz4rdHGu-pUwtf2BnB8MzwvDtOB8AEW6bvFLLTlcxn9mIJVrIWzHFx6qWEdDQO7WlZp0o7MiiOfdfPBacztARRd6XRfPu1sC1Kos0sgy3jCKwVWqVG2fZr47Jfgq8mbJTBzu76UP-wSrG4e9Beay0pN_4HkJT7ybLCmgh_9LHOQ/http%3A%2F%2Fmysticlakesoftware.com%2F"
                          target="_blank" moz-do-not-send="true"> <i>Mystic
                            Lake Software</i> </a> <br>
                        <br>
                      </font> </div>
                    <div>On 12/17/21 3:18 PM, Pat Caron via DPRGlist
                      wrote:<br>
                    </div>
                    <blockquote type="cite">
                      <div dir="ltr">
                        <div class="gmail_default"
                          style="font-size:small">Here is the output
                          from Rud's changes:</div>
                        <div class="gmail_default"
                          style="font-size:small"><br>
                        </div>
                        <div class="gmail_default"
                          style="font-size:small">--- Miniterm on
                          /dev/ttyUSB-sensors  115200,8,N,1 ---<br>
                          --- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T
                          followed by Ctrl+H ---<br>
                          cm[0] = 0 0 999 999<br>
                          cm[1] = 95 95 999 999<br>
                          cm[2] = 91 91 999 999<br>
                          cm[3] = 84 84 999 999<br>
                          cm[4] = 251 251 999 999<br>
                          cm[0] = 0 0 999 999</div>
                        <div class="gmail_default"
                          style="font-size:small">...Pat C.<br>
                        </div>
                      </div>
                      <br>
                      <div class="gmail_quote">
                        <div dir="ltr" class="gmail_attr">On Fri, Dec
                          17, 2021 at 4:04 PM John Swindle via DPRGlist
                          <<a href="mailto:dprglist@lists.dprg.org"
                            target="_blank" moz-do-not-send="true">dprglist@lists.dprg.org</a>>
                          wrote:<br>
                        </div>
                        <blockquote class="gmail_quote"
                          style="margin:0px 0px 0px
                          0.8ex;border-left:1px solid
                          rgb(204,204,204);padding-left:1ex">
                          <div style="color:black;font:10pt
                            Arial,Helvetica,sans-serif"><br>
                            <div>
                              <div
                                style="font-family:arial,helvetica;font-size:10pt;color:black"><font
                                  size="2"> From: Rud Merriam via
                                  DPRGlist <<a
                                    href="mailto:dprglist@lists.dprg.org"
                                    target="_blank"
                                    moz-do-not-send="true">dprglist@lists.dprg.org</a>><br>
                                  To: <a
                                    href="mailto:dprglist@lists.dprg.org"
                                    target="_blank"
                                    moz-do-not-send="true">dprglist@lists.dprg.org</a><br>
                                  Cc: Rud Merriam <<a
                                    href="mailto:rudmerriam@gmail.com"
                                    target="_blank"
                                    moz-do-not-send="true">rudmerriam@gmail.com</a>><br>
                                  Sent: Fri, Dec 17, 2021 2:35 pm<br>
                                  Subject: Re: [Dprglist] Arduino Code
                                  Troubles<br>
                                  <br>
                                  <div
id="gmail-m_6224175929652028693gmail-m_-5425482318595831762gmail-m_2894956073640297808gmail-m_6142257130072753671yiv3997825307">
                                    <div>
                                      <div>Obviously somethine strange
                                        happening. Grasping at a straw
                                        try replacing the 'or' in the
                                        conditional with '||'. It
                                        shouldn't make a difference
                                        but.... <br clear="none">
                                      </div>
                                      <div>Started to make othere
                                        suggestions to localize the
                                        problem but to much verbiage.
                                        Here is what I would try:<br
                                          clear="none">
                                      </div>
                                      <pre>  for (uint8_t x = 0; x < (SONAR_NUM + IR_NUM); x++) {
    Serial.print("cm[");
    Serial.print(x);
    Serial.print("] = ");
    Serial.print(cm[x]);
    Serial.print(" ");

    if ((cm[x] == 0) || (cm[x] > maxDistance)) {
      Serial.print(cm[x]);    //
      Serial.print(" ");

      cm[x] = 999;

      Serial.print(cm[x]);   //
      Serial.print(" ");

    }

    Serial.println(cm[x]);
  }</pre>
                                      <div><br clear="none">
                                      </div>
                                      <div><font face="Comic Sans MS"
                                          color="#000080"> <br
                                            clear="none">
                                          -73 - <br clear="none">
                                          <b>Rud Merriam K5RUD</b> <br
                                            clear="none">
                                          <a rel="nofollow noopener
                                            noreferrer" shape="rect"
href="http://secure-web.cisco.com/1L_tRh7d2I9r0OgjobcEuIU_IszpkQq_xbnOiEo1x0nbY9Kmp2qUGFRPorl51SZ-ZHIkthbQu-To2vCaw9oOiALtmhVTyFIXFLRTHcR9EkjyUtrNpHSakTKr6Uj09uzEvHz4rdHGu-pUwtf2BnB8MzwvDtOB8AEW6bvFLLTlcxn9mIJVrIWzHFx6qWEdDQO7WlZp0o7MiiOfdfPBacztARRd6XRfPu1sC1Kos0sgy3jCKwVWqVG2fZr47Jfgq8mbJTBzu76UP-wSrG4e9Beay0pN_4HkJT7ybLCmgh_9LHOQ/http%3A%2F%2Fmysticlakesoftware.com%2F"
                                            target="_blank"
                                            moz-do-not-send="true"> <i>Mystic
                                              Lake Software</i> </a> <br
                                            clear="none">
                                          <br clear="none">
                                        </font> </div>
                                      <div
id="gmail-m_6224175929652028693gmail-m_-5425482318595831762gmail-m_2894956073640297808gmail-m_6142257130072753671yiv3997825307yqtfd15399">
                                        <div>On 12/17/21 10:13 AM, Pat
                                          Caron via DPRGlist wrote:<br
                                            clear="none">
                                        </div>
                                        <blockquote type="cite"> </blockquote>
                                      </div>
                                    </div>
                                    <div
id="gmail-m_6224175929652028693gmail-m_-5425482318595831762gmail-m_2894956073640297808gmail-m_6142257130072753671yiv3997825307yqtfd69348">
                                      <div>
                                        <div dir="ltr">
                                          <div style="font-size:small"><br
                                              clear="none">
                                            <div style="font-size:small">What
                                              I meant to say last night
                                              is the array size is
                                              cm[8].  The values for
                                              SONAR_NUM == 3 and IR_NUM
                                              == 2<br clear="none">
                                              This should not be
                                              overrunning the array as
                                              it only loops through 5
                                              times.<br clear="none">
                                              I have tried setting
                                              maxDistance as uint32_t
                                              without any difference.</div>
                                            <div style="font-size:small">I
                                              have commented out the
                                              sendData() function and
                                              added some Serial.print
                                              statements prior to
                                              reassigning the values.
                                              (shown in output)</div>
                                            <div style="font-size:small"><br
                                                clear="none">
                                            </div>
                                            <div style="font-size:small">#define
                                              SONAR_NUM 3<br
                                                clear="none">
                                              #define IR_NUM 2<br
                                                clear="none">
                                              uint32_t cm[8] =
                                              {0,0,0,0,0,0,0,0}; //
                                              Create array<br
                                                clear="none">
                                              uint16_t maxDistance =
                                              200; // Also used with
                                              NewPing.h libraray<br
                                                clear="none">
                                              char *position[] =
                                              {"us_Left", "us_Mid",
                                              "us_Right", "ir_Left",
                                              "ir_Right", "cm[5]",
                                              "cm[6]", "cm[7]"};<br
                                                clear="none">
                                              .<br clear="none">
                                              . // Other code here<br
                                                clear="none">
                                              .<br clear="none">
                                              <br clear="none">
                                              void oneSensorCycle() { //
                                              Sensor ping cycle
                                              complete, do something
                                              with the results.<br
                                                clear="none">
                                                for (uint8_t x = 0; x
                                              < (SONAR_NUM + IR_NUM);
                                              x++) {<br clear="none">
                                                  Serial.print("cm[");<br
                                                clear="none">
                                                  Serial.print(x);<br
                                                clear="none">
                                                  Serial.print("] = ");<br
                                                clear="none">
                                                  Serial.println(cm[x]);<br
                                                clear="none">
                                                  if ((cm[x] == 0) or
                                              (cm[x] > maxDistance))
                                              {<br clear="none">
                                                    cm[x] = 999;<br
                                                clear="none">
                                                  }<br clear="none">
                                                }<br clear="none">
                                                if (troubleshoot) {<br
                                                clear="none">
                                                  for (uint8_t i = 0; i
                                              < (SONAR_NUM + IR_NUM);
                                              i++) {<br clear="none">
                                                    Serial.print("| ");<br
                                                clear="none">
                                                   
                                              Serial.print(position[i]);<br
                                                clear="none">
                                                    Serial.print(" = ");<br
                                                clear="none">
                                                    Serial.print(cm[i]);<br
                                                clear="none">
                                                    Serial.print("cm ");<br
                                                clear="none">
                                                  }<br clear="none">
                                                  Serial.print("| ");<br
                                                clear="none">
                                                  Serial.print("Time =
                                              ");<br clear="none">
                                                 
                                              Serial.print(elapsedMillis);<br
                                                clear="none">
                                                  Serial.print("mS");<br
                                                clear="none">
                                                  Serial.println();<br
                                                clear="none">
                                                }<br clear="none">
                                                //else {<br clear="none">
                                                //  sendData();<br
                                                clear="none">
                                                //}<br clear="none">
                                              }<br clear="none">
                                              <br clear="none">
                                              <br clear="none">
                                              Loop() {<br clear="none">
                                            </div>
                                            <div style="font-size:small"> 
                                              .// other code<br
                                                clear="none">
                                            </div>
                                            <div style="font-size:small"> 
                                              oneSensorCycle()<br
                                                clear="none">
                                            </div>
                                            <div style="font-size:small"> 
                                              . // more code<br
                                                clear="none">
                                            </div>
                                            <div style="font-size:small">}<br
                                                clear="none">
                                              <br clear="none">
                                              Serial output:<br
                                                clear="none">
                                              <br clear="none">
                                              -- Miniterm on
                                              /dev/ttyUSB-sensors
                                               115200,8,N,1 ---<br
                                                clear="none">
                                              --- Quit: Ctrl+C | Menu:
                                              Ctrl+T | Help: Ctrl+T
                                              followed by Ctrl+H ---<br
                                                clear="none">
                                              cm[0] = 0<br clear="none">
                                              cm[1] = 95<br clear="none">
                                              cm[2] = 91<br clear="none">
                                              cm[3] = 85<br clear="none">
                                              cm[4] = 246<br
                                                clear="none">
                                              | us_Left = 999cm | us_Mid
                                              = 999cm | us_Right = 999cm
                                              | ir_Left = 999cm |
                                              ir_Right = 999cm | Time =
                                              44mS<br clear="none">
                                              <br clear="none">
                                              ...Pat C<br clear="none">
                                              <br clear="none">
                                            </div>
                                          </div>
                                        </div>
                                        <br clear="none">
                                        <div>
                                          <div dir="ltr">On Fri, Dec 17,
                                            2021 at 10:07 AM Chris
                                            Netter <<a rel="nofollow
                                              noopener noreferrer"
                                              shape="rect"
                                              href="mailto:netterchris@gmail.com"
                                              target="_blank"
                                              moz-do-not-send="true">netterchris@gmail.com</a>>
                                            wrote:<br clear="none">
                                          </div>
                                          <blockquote style="margin:0px
                                            0px 0px
                                            0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
                                            <div lang="EN-US">
                                              <div>
                                                <div>The for loop stops
                                                  at x < 8, so it
                                                  won’t overrun.</div>
                                                <div> </div>
                                                <div>What if you remove
                                                  the sendData() call? 
                                                  Does that help?</div>
                                                <div> </div>
                                                <div>Also,  make sure
                                                  you have declared any
                                                  global variables which
                                                  are modified by
                                                  interrupts or other
                                                  tasks as “volatile”,
                                                  otherwise the compile
                                                  may decide to optimize
                                                  away parts of your
                                                  code.</div>
                                                <div> </div>
                                                <div>Chris</div>
                                                <div> </div>
                                                <div
                                                  style="border-color:rgb(225,225,225)
                                                  currentcolor
                                                  currentcolor;border-style:solid
                                                  none
                                                  none;border-width:1pt
                                                  medium
                                                  medium;padding:3pt 0in
                                                  0in">
                                                  <div
                                                    style="border:medium
                                                    none;padding:0in"><b>From:
                                                    </b><a rel="nofollow
                                                      noopener
                                                      noreferrer"
                                                      shape="rect"
                                                      href="mailto:paradug@gmail.com"
                                                      target="_blank"
                                                      moz-do-not-send="true">Doug
                                                      Paradis</a><br
                                                      clear="none">
                                                    <b>Sent: </b>Thursday,
                                                    December 16, 2021
                                                    11:46 PM<br
                                                      clear="none">
                                                    <b>To: </b><a
                                                      rel="nofollow
                                                      noopener
                                                      noreferrer"
                                                      shape="rect"
                                                      href="mailto:netterchris@gmail.com"
                                                      target="_blank"
                                                      moz-do-not-send="true">Chris
                                                      Netter</a><br
                                                      clear="none">
                                                    <b>Cc: </b><a
                                                      rel="nofollow
                                                      noopener
                                                      noreferrer"
                                                      shape="rect"
                                                      href="mailto:patcaron@mail.com"
                                                      target="_blank"
                                                      moz-do-not-send="true">Pat
                                                      Caron</a>; <a
                                                      rel="nofollow
                                                      noopener
                                                      noreferrer"
                                                      shape="rect"
                                                      href="mailto:dprglist@lists.dprg.org"
                                                      target="_blank"
                                                      moz-do-not-send="true">dprglist@lists.dprg.org</a><br
                                                      clear="none">
                                                    <b>Subject: </b>Re:
                                                    [Dprglist] Arduino
                                                    Code Troubles</div>
                                                </div>
                                                <div> </div>
                                                <div>
                                                  <div>Pat,</div>
                                                  <div>
                                                    <div>    for
                                                      (uint8_t x = 0; x
                                                      < (SONAR_NUM +
                                                      IR_NUM); x++) {</div>
                                                  </div>
                                                  <div>
                                                    <div> </div>
                                                  </div>
                                                  <div>
                                                    <div>    If 
                                                      SONAR_NUM _ IR_NUM
                                                      = 8 then you are
                                                      overrunning the
                                                      array which goes 0
                                                      to 7.</div>
                                                  </div>
                                                  <div>
                                                    <div> </div>
                                                  </div>
                                                  <div>
                                                    <div>Regards,</div>
                                                  </div>
                                                  <div>
                                                    <div>Doug P.</div>
                                                  </div>
                                                </div>
                                                <div> </div>
                                                <div>
                                                  <div>
                                                    <div>On Thu, Dec 16,
                                                      2021 at 8:53 PM
                                                      Chris Netter via
                                                      DPRGlist <<a
                                                        rel="nofollow
                                                        noopener
                                                        noreferrer"
                                                        shape="rect"
                                                        href="mailto:dprglist@lists.dprg.org"
                                                        target="_blank"
moz-do-not-send="true">dprglist@lists.dprg.org</a>> wrote:</div>
                                                  </div>
                                                  <blockquote
                                                    style="border-color:currentcolor
                                                    currentcolor
                                                    currentcolor
                                                    rgb(204,204,204);border-style:none
                                                    none none
                                                    solid;border-width:medium
                                                    medium medium
                                                    1pt;padding:0in 0in
                                                    0in
                                                    6pt;margin-left:4.8pt;margin-right:0in">
                                                    <div>
                                                      <div>
                                                        <div>So Markus
                                                          and Karim
                                                          already
                                                          pointed out
                                                          that the
                                                          original code
                                                          snipped works
                                                          as designed.</div>
                                                        <div> </div>
                                                        <div>It’s also
                                                          been pointed
                                                          out already
                                                          that you are
                                                          mixing data
                                                          types. I don’t
                                                          think that’s
                                                          the issue, but
                                                          worth trying
                                                          to make both
                                                          the array and
                                                          maxDistance
                                                          uint16_t</div>
                                                        <div> </div>
                                                        <div>As for this
                                                          new code
                                                          snippet:</div>
                                                        <div> </div>
                                                        <div>I don’t see
                                                          any obvious
                                                          issue with the
                                                          for loop.  Are
                                                          you positive
                                                          that <span
                                                          style="font-size:12pt">SONAR_NUM
                                                          + IR_NUM == 8
                                                          ?   if not,
                                                          you are
                                                          overshooting
                                                          the array and
                                                          that can cause
                                                          all kinds of
                                                          non-obvious
                                                          issues.</span></div>
                                                        <div><span
                                                          style="font-size:12pt"> </span></div>
                                                        <div><span
                                                          style="font-size:12pt">Also,
                                                          what does
                                                          sendData()
                                                          do?  Could it
                                                          have some
                                                          side-effects?  
                                                          Maybe its
                                                          causing a
                                                          stack
                                                          overflow,
                                                          array bounds
                                                          overflow, or
                                                          similar, which
                                                          in turn causes
                                                          non-obvious
                                                          issues?</span></div>
                                                        <div> </div>
                                                        <div> </div>
                                                        <div> </div>
                                                        <div
                                                          style="border-color:rgb(225,225,225)
                                                          currentcolor
                                                          currentcolor;border-style:solid
                                                          none
                                                          none;border-width:1pt
                                                          medium
                                                          medium;padding:3pt
                                                          0in 0in">
                                                          <div><b>From:
                                                          </b><a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:dprglist@lists.dprg.org"
target="_blank" moz-do-not-send="true">Pat Caron via DPRGlist</a><br
                                                          clear="none">
                                                          <b>Sent: </b>Thursday,
                                                          December 16,
                                                          2021 9:04 PM<br
                                                          clear="none">
                                                          <b>To: </b><a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:dprglist@lists.dprg.org"
target="_blank" moz-do-not-send="true">dprglist@lists.dprg.org</a><br
                                                          clear="none">
                                                          <b>Subject: </b>Re:
                                                          [Dprglist]
                                                          Arduino Code
                                                          Troubles</div>
                                                        </div>
                                                        <div> </div>
                                                        <div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt">Hi
                                                          guys, here is
                                                          a better
                                                          example to
                                                          show what is
                                                          happening
                                                          taken from
                                                          actual code:</span></div>
                                                          </div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt"> </span></div>
                                                          </div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt">....
                                                          other code<br
                                                          clear="none">
                                                            for (uint8_t
                                                          x = 0; x <
                                                          (SONAR_NUM +
                                                          IR_NUM); x++)
                                                          {  //
                                                          SONAR_NUM +
                                                          IR_NUM = 8<br
                                                          clear="none">
                                                              if ((cm[x]
                                                          == 0) ||
                                                          (cm[x] >
                                                          maxDistance))
                                                          {<br
                                                          clear="none">
                                                                cm[x] =
                                                          999;<br
                                                          clear="none">
                                                              }</span></div>
                                                          </div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt"> 
                                                          sendData();</span></div>
                                                          </div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt"> 
                                                          }<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          Printed values
                                                          cm[0] to cm[5]
                                                          (us_Left to
                                                          ir_Right)
                                                          without the
                                                          above if
                                                          statement<br
                                                          clear="none">
                                                          | us_Left =
                                                          0cm | us_Mid =
                                                          95cm |
                                                          us_Right =
                                                          51cm | ir_Left
                                                          = 84cm |
                                                          ir_Right =
                                                          252cm | Time =
                                                          45mS<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          Printed values
                                                          cm[0] to cm[5]
                                                          with the above
                                                          if statement<br
                                                          clear="none">
                                                          \| us_Left =
                                                          999cm | us_Mid
                                                          = 999cm |
                                                          us_Right =
                                                          999cm |
                                                          ir_Left =
                                                          999cm |
                                                          ir_Right =
                                                          999cm | Time =
                                                          44mS<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          ...Pat C</span></div>
                                                          </div>
                                                        </div>
                                                        <div> </div>
                                                        <div>
                                                          <div>
                                                          <div>On Thu,
                                                          Dec 16, 2021
                                                          at 8:45 PM
                                                          Karim Virani
                                                          <<a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:pondersome64@gmail.com"
target="_blank" moz-do-not-send="true">pondersome64@gmail.com</a>>
                                                          wrote:</div>
                                                          </div>
                                                          <blockquote
                                                          style="border-color:currentcolor
                                                          currentcolor
                                                          currentcolor
                                                          rgb(204,204,204);border-style:none
                                                          none none
                                                          solid;border-width:medium
                                                          medium medium
1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
                                                          <div>
                                                          <div>It's
                                                          doing what
                                                          it's coded to
                                                          do</div>
                                                          </div>
                                                          <div> </div>
                                                          <div>
                                                          <div>
                                                          <div>On Thu,
                                                          Dec 16, 2021
                                                          at 7:42 PM Pat
                                                          Caron via
                                                          DPRGlist <<a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:dprglist@lists.dprg.org"
target="_blank" moz-do-not-send="true">dprglist@lists.dprg.org</a>>
                                                          wrote:</div>
                                                          </div>
                                                          <blockquote
                                                          style="border-color:currentcolor
                                                          currentcolor
                                                          currentcolor
                                                          rgb(204,204,204);border-style:none
                                                          none none
                                                          solid;border-width:medium
                                                          medium medium
1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
                                                          <div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt">Hi
                                                          Murray, I did
                                                          try that with
                                                          the same
                                                          results. 
                                                          NewPing.h
                                                          library is
                                                          looking for a
                                                          uint16_t
                                                          although it
                                                          didn't
                                                          complain when
                                                          I tried that.</span></div>
                                                          </div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt"> </span></div>
                                                          </div>
                                                          <div>
                                                          <div><span
                                                          style="font-size:12pt">...Pat
                                                          C</span></div>
                                                          </div>
                                                          </div>
                                                          <div> </div>
                                                          <div>
                                                          <div>
                                                          <div>On Thu,
                                                          Dec 16, 2021
                                                          at 8:35 PM
                                                          Murray Altheim
                                                          via DPRGlist
                                                          <<a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:dprglist@lists.dprg.org"
target="_blank" moz-do-not-send="true">dprglist@lists.dprg.org</a>>
                                                          wrote:</div>
                                                          </div>
                                                          <blockquote
                                                          style="border-color:currentcolor
                                                          currentcolor
                                                          currentcolor
                                                          rgb(204,204,204);border-style:none
                                                          none none
                                                          solid;border-width:medium
                                                          medium medium
1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
                                                          <div>Hi Pat,<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          What if you
                                                          define
                                                          maxDistance as
                                                          uint32_t?<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          Cheers,<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          Murray<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          On 17/12/21
                                                          2:27 pm, Pat
                                                          Caron via
                                                          DPRGlist
                                                          wrote:<br
                                                          clear="none">
                                                          > Hi guys,
                                                          I'm looking
                                                          for help with
                                                          the following
                                                          Arduino code.<br
                                                          clear="none">
                                                          > <br
                                                          clear="none">
                                                          >     
                                                          uint32_t cm[8]
                                                          =
                                                          {0,0,0,0,0,0,0,0};
                                                          // Create
                                                          array<br
                                                          clear="none">
                                                          >     
                                                          uint16_t
                                                          maxDistance =
                                                          200; // Also
                                                          used with
                                                          NewPing.h
                                                          library<br
                                                          clear="none">
                                                          >      .<br
                                                          clear="none">
                                                          >      . //
                                                          Other code
                                                          here<br
                                                          clear="none">
                                                          >      .<br
                                                          clear="none">
                                                          >     
                                                          irSensorL.read();
                                                          // Read IR
                                                          sensor... This
                                                          is working!<br
                                                          clear="none">
                                                          >     
                                                          cm[3] =
irSensorL.ranging_data.range_mm/10; // This returns 268<br clear="none">
                                                          >      if
                                                          (cm[3] >
                                                          maxDistance) {<br
                                                          clear="none">
                                                          >       
                                                          cm[3] = 999;  
                                                                       
                                                          /<br
                                                          clear="none">
                                                          >      }<br
                                                          clear="none">
                                                          >     
                                                          Serial.println(cm[3]); 
                                                          / cm[3] value
                                                          is always =
                                                          999<br
                                                          clear="none">
                                                          >     
                                                          sendData();<br
                                                          clear="none">
                                                          > <br
                                                          clear="none">
                                                          > The cm[3]
                                                          value is
                                                          always 999
                                                          when I run
                                                          this.<br
                                                          clear="none">
                                                          > If I
                                                          comment out
                                                          the if
                                                          cm[3]...
                                                          statement
                                                          cm[3] value is
                                                          then 268.<br
                                                          clear="none">
                                                          > <br
                                                          clear="none">
                                                          > ...Pat C<br
                                                          clear="none">
                                                          > <br
                                                          clear="none">
                                                          >
                                                          _______________________________________________<br
                                                          clear="none">
                                                          > DPRGlist
                                                          mailing list<br
                                                          clear="none">
                                                          > <a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:DPRGlist@lists.dprg.org"
target="_blank" moz-do-not-send="true">DPRGlist@lists.dprg.org</a><br
                                                          clear="none">
                                                          > <a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org"
target="_blank" moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a><br
                                                          clear="none">
                                                          > <br
                                                          clear="none">
                                                          <br
                                                          clear="none">
                                                          -- <br
                                                          clear="none">
                                                          <br
                                                          clear="none">
.........................................................................<br
                                                          clear="none">
                                                          Murray Altheim
                                                          <murray18
                                                          at altheim dot
                                                          com>       
                                                                       
                                                           = =  ===<br
                                                          clear="none">
                                                          <a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
href="http://secure-web.cisco.com/14lOvdPcUGlPjP2ivAKeY8mIi9d295v8OaWJdPND2YjUJlBfNoOO3lETTilwP_3nz0RxT_U1mFErnHiwcJer8prIocqg1sJt81nvC7gdyvvJu7aQwIQEMibN8VF9PjYveDL1bpo-ujILuQozSyYctFPs7EbE9iq2qYCLgM7cqbhW1o1TCZJILl9ZYfxcnrU8lgsJgJNKGYbSIQXO1xsNWAGR_pVFbNDn02LdLUm-BM_5vLawr0NVyH33Qv4Bc5esdpP5qVQcKHPoVlY-u4XYg3siPzxpb5tlZzRxG_qE5Ma8/http%3A%2F%2Fwww.altheim.com%2Fmurray%2F"
target="_blank" moz-do-not-send="true">http://www.altheim.com/murray/</a> 
                                                                       
                                                                       
                                                                 === 
                                                          ===<br
                                                          clear="none">
                                                                       
                                                                       
                                                                       
                                                                       
                                                                      =
                                                          =  ===<br
                                                          clear="none">
                                                               In the
                                                          evening<br
                                                          clear="none">
                                                               The rice
                                                          leaves in the
                                                          garden<br
                                                          clear="none">
                                                               Rustle in
                                                          the autumn
                                                          wind<br
                                                          clear="none">
                                                               That
                                                          blows through
                                                          my reed hut.<br
                                                          clear="none">
                                                                      --
                                                          Minamoto no
                                                          Tsunenobu<br
                                                          clear="none">
                                                          <br
                                                          clear="none">
_______________________________________________<br clear="none">
                                                          DPRGlist
                                                          mailing list<br
                                                          clear="none">
                                                          <a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:DPRGlist@lists.dprg.org"
target="_blank" moz-do-not-send="true">DPRGlist@lists.dprg.org</a><br
                                                          clear="none">
                                                          <a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org"
target="_blank" moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a></div>
                                                          </blockquote>
                                                          </div>
                                                          </blockquote>
                                                          </div>
                                                          </blockquote>
                                                        </div>
                                                        <div
                                                          style="margin-left:9.6pt">_______________________________________________<br
                                                          clear="none">
                                                          DPRGlist
                                                          mailing list<br
                                                          clear="none">
                                                          <a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="mailto:DPRGlist@lists.dprg.org"
target="_blank" moz-do-not-send="true">DPRGlist@lists.dprg.org</a><br
                                                          clear="none">
                                                          <a
                                                          rel="nofollow
                                                          noopener
                                                          noreferrer"
                                                          shape="rect"
                                                          href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org"
target="_blank" moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a></div>
                                                        <div> </div>
                                                      </div>
                                                    </div>
                                                  </blockquote>
                                                </div>
                                                <div
                                                  style="margin-left:4.8pt">_______________________________________________<br
                                                    clear="none">
                                                  DPRGlist mailing list<br
                                                    clear="none">
                                                  <a rel="nofollow
                                                    noopener noreferrer"
                                                    shape="rect"
                                                    href="mailto:DPRGlist@lists.dprg.org"
                                                    target="_blank"
                                                    moz-do-not-send="true">DPRGlist@lists.dprg.org</a><br
                                                    clear="none">
                                                  <a rel="nofollow
                                                    noopener noreferrer"
                                                    shape="rect"
                                                    href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org"
                                                    target="_blank"
                                                    moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a></div>
                                                <div> </div>
                                              </div>
                                            </div>
                                          </blockquote>
                                        </div>
                                        <br clear="none">
                                        <fieldset></fieldset>
                                        <pre>_______________________________________________
DPRGlist mailing list
<a rel="nofollow noopener noreferrer" shape="rect" href="mailto:DPRGlist@lists.dprg.org" target="_blank" moz-do-not-send="true">DPRGlist@lists.dprg.org</a>
<a rel="nofollow noopener noreferrer" shape="rect" href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org" target="_blank" moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a>
</pre>
                                      </div>
                                    </div>
                                  </div>
                                  <div
id="gmail-m_6224175929652028693gmail-m_-5425482318595831762gmail-m_2894956073640297808gmail-m_6142257130072753671yqtfd06328">_______________________________________________<br
                                      clear="none">
                                    DPRGlist mailing list<br
                                      clear="none">
                                    <a shape="rect"
                                      href="mailto:DPRGlist@lists.dprg.org"
                                      target="_blank"
                                      moz-do-not-send="true">DPRGlist@lists.dprg.org</a><br
                                      clear="none">
                                    <a shape="rect"
                                      href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org"
                                      target="_blank"
                                      moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a><br
                                      clear="none">
                                  </div>
                                </font></div>
                            </div>
                          </div>
_______________________________________________<br>
                          DPRGlist mailing list<br>
                          <a href="mailto:DPRGlist@lists.dprg.org"
                            target="_blank" moz-do-not-send="true">DPRGlist@lists.dprg.org</a><br>
                          <a
                            href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org"
                            rel="noreferrer" target="_blank"
                            moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a><br>
                        </blockquote>
                      </div>
                      <br>
                      <fieldset></fieldset>
                      <pre>_______________________________________________
DPRGlist mailing list
<a href="mailto:DPRGlist@lists.dprg.org" target="_blank" moz-do-not-send="true">DPRGlist@lists.dprg.org</a>
<a href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org" target="_blank" moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a>
</pre>
                    </blockquote>
                  </div>
                  _______________________________________________<br>
                  DPRGlist mailing list<br>
                  <a href="mailto:DPRGlist@lists.dprg.org"
                    target="_blank" moz-do-not-send="true">DPRGlist@lists.dprg.org</a><br>
                  <a
                    href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a><br>
                </blockquote>
              </div>
            </blockquote>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
DPRGlist mailing list
<a class="moz-txt-link-abbreviated" href="mailto:DPRGlist@lists.dprg.org">DPRGlist@lists.dprg.org</a>
<a class="moz-txt-link-freetext" href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a>
</pre>
    </blockquote>
  </body>
</html>