![]() ![]() Scaffolding allows you to leave all of the debug statements in the code if you wish, but comment out the #define and you can see the actual code size, less the debug statements. Because DEBUG1 is not defined, that debug sequence is removed, but any others in the program remain active. Now, after you no longer need the debug code, you can do one of two things: 1) comment out the #define DEBUG 1 line, which silences all debug print statement in the program, or 2) change the line in the for loop to #ifdef DEBUG1. You might place the following inside the for loop: #ifdef DEBUG Now suppose you need to inspect an array value in a for loop. If your code doesn't already use the Serial object, then add this to setup(): #ifdef DEBUG Scaffolding involves placing the following line at the top of your code: #define DEBUG 1 Scaffold code is another technique to use. You can also start off with dummy functions that allow the rest of the program to be compiled and tested.Īnd, when starting on something new, ask yourself "if this doesn't work how will I know" and maybe add extra code specially for debugging. That is a great help with separating sometimes complex decision logic from the activities that the decisions control, or from which they get their input. I also find it very useful to develop my code as small functions that clearly separate the functionality and make the code easy to follow. ![]() That way if you have a question for the forum it can be specific and not "Help, my code doesn't work, what's wrong" followed by 200 lines of complex code where the error could be anywhere. ![]() Another option is to have LEDs switch on and off to signify progress through your code, but then you have to remember what they signify!Ī very important element is to develop your project in small chunks and make sure each works and that you understand it before adding further features. Debugging Arduino code isn't quite the same as debugging code for a PC because the Arduino code is usually controlling physical outputs or receiving physical inputs to/from the real world and the debugging process has to take those into account.Īs others have said, using Serial.println() is the usual tool to monitor what's happening. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |