Serial debugging: Sign posts
One very useful serial technique is what I call signposts. You simply insert a bit of code at strategic parts of a program to see where it is going. This is particularly useful if it looks like your program is getting lost or never getting to an important part. Maybe your program fails to turn off the fill valve when the vessel is full (hopefully you are bench testing this, so no physical harm is being done!). The program will contain a chain of events that leads, ultimately to the crucial valve being turned off, but for some reason it never gets to the turnoff instruction.
What you do is scatter a number of simple iiPrintText instructions throughout the relevant code. Let’s say you simply use
iiPrintText 251,"A"
......
iiPrintText 251,"B"
......
iiPrintText 251,"C"
......
iiPrintText 251,"D"
......
where the dots represent your regular program code. It’s really easy to insert those line, by using copy and paste and a simple edit on each sign post. Now you run your program and do to it those things that should lead to the valve turning off, and note which of the sign posts get displayed on the terminal. Say it displays A and B, but never reaches C. It must be getting lost between B and C.
Go to the section of code between B and C and insert several more sign posts, say B1, B2, B3 etc. Run the program again. Soon you will be homing in on the exact point where it is mis-stepping. Maybe you have a GoIfT instead of a GoIfF, or you used a Recall rather than a RecallS. Those kinds of coding typos can be very hard to spot, but with sign posts you can home in on them very quickly.
When you have found the bug, go through and delete the sign posts. They are so easy to create that they are not worth keeping.