Breaking up code in multiple files

A place to just chat
Post Reply
blaketasim
Posts: 4
Joined: Thu Nov 23, 2023 5:14 am

Thu Nov 23, 2023 5:22 am

I've been trying to program a teensy 4.1. When i smash everything into the main .ino file, i have no problems.

When i try to use pointers or move any reference outside of the main file i run into serious problems.

First is passing a function into the command handler. It seems like the only way to do this is by defining it in the main ino. is that correct?

Second, say i want another class to run some procedure, update a value, then send the updated value to megulink. If that code is defined in another file, i have to pass a reference into the object. If i turn mypanel into a pointer, everything breaks.

If anyone has any tips/thoughts, i'd appreciate it.

Blake
strud
Posts: 21
Joined: Sat Nov 18, 2023 6:51 am

Sun Nov 26, 2023 8:32 pm

Hi Blake,

I am using a Teensy 4.1 and developing in VS Code using Platform IO.

I had lots of issues in the Arduino IDE when trying to break my code up into multiple files. I even discovered it mattered which order the files where arranged in the tabbed view of the IDE when compiling!

I changed over to VS Code and Platform IO for these reasons and much more.

Strud
blaketasim
Posts: 4
Joined: Thu Nov 23, 2023 5:14 am

Mon Nov 27, 2023 5:40 pm

Hi Strud,

I'm using VS code as well but on PC.

Everything compiles fine, but when i upload the code, my teensy board just freeze.

I'm still using multiple files, i'm just leaving all of the megunolink files in the main ino and that seems to be okay. My main is just getting very clunky.

Blake
strud
Posts: 21
Joined: Sat Nov 18, 2023 6:51 am

Tue Nov 28, 2023 8:25 pm

Hi Blake,

All I can suggest is old fashioned stops like while(1) in places early in your code until you get to the problem area.....

Are you using interrupts? Is there any chance you have one that is being triggered too often and starving the main loop for example?


I'm using PlatformIO and I don't have any issues when breaking up code into multiple files. My project has grown quite a bit and I am still in the process of refactoring to make the main file more manageable (currently > 10k lines) .
Post Reply