A program gets stuck in changing places


I'm sorry, but I can't send program code.
I am using Arduino Due and arduino version 1.8.15.
At the beginning of the program, a function is called, the beginning of which essentially looks like this (I only put this together on the original sample, which I can't send. I'm sorry and I know how difficult it is to help)

void function() 
  Serial.println("Text 1");
  int variable1 = 0;
  int variable2 = 1;
  int variable3 = 2;
  Serial.println("Text 2");
  for(int i=0; i<28; i++)
    variable1 = variable1 + i ;

The problem:
When for reaches a value of 23 then only "text" is printed with a value of 23 for no. This takes on the same value in the original program. When I rewrote it to start from 27 instead of 1, it ran normally and ran on.
When it started with a value between 23 and 26, "Text 1" wasn't written out either.

It is also strange that the print stops at half the text.
What can cause such a problem?

Unfortunately, I can't send the original program code. Anyone who is still trying to help its thanks in advance.

Even if you can't post the original code for some reason, please post a complete sketch that shows the problem so that others can try it for themselves

Why not?

What kind of sketched packs can I try with?
I can't put up the function. How do I send something they can try without sending the function?

With the full example sketch in the IDE use Auto Format to tidy it up then right click and Copy for forum and paste it in a new post here

I may misunderstand what you are saying but
I can't paste my program as I wrote
The example I sent is just an illustration. That's not a working sketch. I just wrote it quickly to make it easier for me to explain what the problem was.
I can add a void loop () and void setup () to it, but it wouldn't make any sense.

Your problem lies in the code that you didn't post.
If you are unwilling to post it, there is very little we can do to help, except offer sympathy.

Yesterday I had a problem with my car so I went to the mechanic. I explained the problem I had with the car, but he was not able to solve the problem from my explanation, so he offered me to look at the car to be sure. But since I left the car at home I did not get my problem fixed, D'OH!

Here is your solution.

1 Like

I shouldn't publish the code like I said.
I won't even send the code. I will ignore any comments on this from now on.

And the mechanic, if for sure, would have an idea of what might be causing the problem.
Especially so that no 2 people turn to this site to see if the arduino has produced something similar to another and then they can tell me what was the source of the problem.

The source of your problem is in the code you didn't post.
That should narrow things down a bit.

Your function works fine. The one you did deign to share.

When I rewrote it to start from 27 instead of 1

What do you mean by that? How would we do this with the function you posted?

Write a small program, complete, that compile, runs and demonstrates the problem.

Not code that looks like what you think is going wrong, something that actually malfunctions in the same manner.


Don't forget to tell him what colour your car is.

A salutory debug lesson

1 Like

For me, it caused something similar when a function was expecting a float value and I gave it an int value. I didn't have the problem right away. :grin:

I hope I could help.

1 Like

Calling a method for function may insult the compiler, so try to give it another name :smirk:

Thanks for the help.

Well, that's clearly not the case in the code posted.

I guess we'll never know.

What a waste of time

I also thanked him for his answer because his help helped him find the error.

You didn't have to write. I described at the beginning that I would not send code. In principle, you read and understood it. If you still write an answer is your fault then wasting time is also your fault.

I wrote early-on that the problem was in the code that you didn't post, and I wasn't wrong.

Welcome to my ignore file.

1 Like

You don't have to post the actual code. But as requested in the first reply, you could post a simple sketch that calls your function and exhibits the behaviour of your secret sketch.

You will probably not able to create such a sketch which indicates that the problem is elsewhere in your secret sketch and you have a pointer.

So what was the problem? What fixed it?

I am surely not the only one who would like to know and I will cheerful admit I might even learn something.

You could take half a minute and share, it might help us not be so unhelpful the next time.

It’s really part of the implicit contract here…



1 Like