Wrong pins are turning on. Bug?

Here is my project.
Weather magnet

I use 4digit 7 segment display. I store 4 values, one for each digit and keep refreshing the display. I get a weird bug.
Some bits are turned on even when they are off in the stored values. See line numbers 171 to 178 of the application.cpp. I get the error, if I replace the block(lines 171 to 178) with interval = intervalAfterFirstUpdate;Crazy…

How can you reproduce this error?
Do the above mentioned code change.
Add the following lines in the beginning of the function setSegmentValues


Run the code.
Connect a led between the pins (D5 and D0) or (A3 and D0) and it shouldn’t be on but it is.

First your interval variables should be unsigned long rather than long int and I’d also do your array init differently


should rather be one of the following

  memset(w_temp, 0, sizeof(w_temp));
  memset(w_id, 0, sizeof(w_id));
  // or less common
  memset(&w_temp[0], 0, sizeof(w_temp));
  memset(&w_id[0], 0, sizeof(w_id));

With your version you may overwrite some memory you don’t intend to touch :wink:


Thanks for your time @ScruffR
I tried your suggestions and it didn’t work.
Anyway, those lines were borrowed from @peekay123 's Code

I see, but symptoms like you mentioned in your code

often point towards memory corruptions due to bad indexing, buffer overflows and such things.

If you try moving this block further down step-by-step and watch when the issue starts appearing, you may find the code section to further investigate.

BTW, in @peekay123’s code these arrays are global while they are automatic (local, stack based) in your case.

And in order to analyse the code of void processWeather(const char *event, const char *data) a comment stating a representative sample for the data field would help.


I understand your comments and suggestions. I will try that. Thanks again for your suggestions.
But, here is my concern. If you look at the comment at line number 93 , adding || (temp < 100 && !minus) to that ternary condition is reintroducing the error even with the code block. Also moving the unrelated code block to debug is kind of blind. Am I not doing anything right?
Also a basic question. would my variable w_temp work for variable work for data value 800~-100.81? I think no. I should increase the size to 8.
I have added the sample data in the new commit.