O'Reilly logo

Arduino Sketches: Tools and Techniques for Programming Wizardry by James A. Langbridge

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER4

The Arduino Language

Functionality can be added to Arduino programs using libraries, but every Arduino project invariably starts with one library; the Arduino Language. The Arduino Language contains everything required for basic programs, allowing access to input and output pins, mathematical functions, and control structures. This chapter lists those functions and gives an explanation of each one. You can also consult the Arduino reference page at http://arduino.cc/en/Reference/.

I/O Functions

An Arduino is a powerful system, but its power comes from interacting with the real world. To do this, the Arduino must use Input and Output, shortened to I/O. Pins can be defined as either being an input or output; it is up to you to decide.

Digital I/O

Digital I/O is defined as using a digital signal to communicate; a logical 1 or logical 0. In Arduino, 1 is defined as having a “high” voltage; normally at or close to the system voltage. 0 is defined as having a “low” voltage, typically 0. A system powered by 5 volts will usually have 5 volts for a logical 1 and 0 volt for a logical 0. A system powered by 3.3 V will usually have 3.3 V and 0.

Examples of digital inputs are switches, like push buttons or contact switches. They are either on or off; there are no values in between.

pinMode()

Before using a pin as a digital input or output, you must first configure the pin, which is done with pinMode(). pinMode() uses two parameters: pin and mode.

pinMode(pin, mode)

The pin parameter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required