24 Arduino Quick Reference

The definitive reference for the Arduino language and libraries is at https://www.arduino.cc/reference/en/, however a shorter list of important elements for starting out is given below. The functions in Red are usually used within the setup() function of the sketch to initialize the setup before going into the repeated execution of the loop function.

Use #include at the top to import the definition files for any extra libraries.

Use #define at the top to define substitutions for elements used throughout the sketch.

Put text between /* */  or on a line after  //  for comments.

Declarations of Variables for Data Types of floatintunsignedunsigned long, and void. Sometimes with the qualifier of  static.

Sketch Structure with functions setup() and loop() and control structure inside functions with forif…elsereturn and while.

The usual Comparison Operators for control structures including != (not equal to), <, <=, == (equal to), >, >= that can be combined with the Boolean Operators ! (logical not), && (logical and), || (logical or) to make complicated conditions.

Equations with the usual Arithmetic Operators including = for assignment, % for modulo and +,-,*,/.

Serial Communication to the Monitor with Serial.begin() and Serial.print() or Serial.printf() if your board supports it.

Digital Input/Output using pinMode()digitalRead() and digitalWrite()

Analog Input/Output using analogReference()analogRead() and analogWrite()

Timing using micros(), while trying to avoid millis(), delay() and delayMicroseconds() because millis() is often only approximate, and delays stop all execution and prevent other important operations from continuing.

Math with abs(), max(), min(), sqrt(), cos(), sin(), tan(), random() doing what you would expect with numerical values.

License

Icon for the Creative Commons Attribution-ShareAlike 4.0 International License

Rick's Measurement for Mechatronics Notes Copyright © 2019 by Rick Sellens is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book