0

Soccer Robot C - Basic lessons - Errors

After You write Your program, Arduino IDE must compile it to machine language. That is what happens when You press Nike (check) button or upload button. If there are errors in Your code, Arduino will report them. Unfortunately, the report is cryptic and sometimes not helpful at all. It may be very difficult to find the source of the errors. You have some strategies at You disposal which can help.
  • Look at the first error in the report. There may be number of the program line that caused the problem. Take a look at the reported line or lines that precede it. However, if the part of the process called "linking" found the problem, no line will be reported.
  • Use Ctrl-Z (undo) as often as possible. Repeat the sequence Ctrl-Z,..., Ctrl-z, compile, Ctrl-Z, ..., Ctrl-Z, compile, ... Continue doing so till You revert the code to a version that compiles.
  • Compile often. If You add 10 lines and find immediately the code causes an error, it will not be hard to find the source. However, if You add 50 lines, scattered in different parts of code, close Arduino IDE and open it again, only to find that the version doesn't compile, You will be in an unenviable position. Reopening Arduino IDE deleted undo-history and You may be forced to find all the places where You made changes.
  • Comment parts of the code. Comments are explained later in lessons. For example, if You added a block of 20 lines, You can comment first 10 and try to compile. If the program compiles, that means the error is in the commented part. Continue commenting or uncommenting until You reduce error source to a single line.