C++ Programming Errors

In working on some Arduino projects, the primary language of sketches is C++, though hidden under the Arduino IDE. ┬áIn order to be more efficient, I’d like to understand more about how errors creep into designs, so that they can be avoided in the future.

Early days in programming, syntax errors at compile time are more frequent, and many times they are a barrier – usually taking much less to debug than runtime errors, but time consuming nevertheless.

Compile Errors – Header

  • include the wrong header file
  • delay() not in scope (need to add <Arduino.h>
  • include header file after reference to type
  • not include header file for each function
  • no need to include file if in same folder as .ino file
  • SoftwareSerial object not declared in this scope (resolved by passing class objects as parameters)

Compile Errors – Scope

  • variable scope defined inside case statement (should be outside)
  • typo – printLN, should be println
  • typo – used wrong variable name (buttonTime versus button1Time)

Installation Errors

  • Should install ubuntu applications in Home, not in Downloads

Runtime Errors

  • Logical error – ‘getAge’ object should not be called until button pressed and flag set (keep logic simple)
  • Syntax error – did not update variable holding member data after updating it (avoid new variables)
  • Syntax error – referred to wrong member attribute (timePB versus _pinTime)




This entry was posted in Arduino, How To, Problem Solving and tagged , , . Bookmark the permalink.

Comments are closed.