Skip to Content
Getting Started with Arduino
book

Getting Started with Arduino

by Massimo Banzi
February 2009
Beginner
128 pages
2h 45m
English
O'Reilly Media, Inc.
Content preview from Getting Started with Arduino

INPUT AND OUTPUT FUNCTIONS

Arduino includes functions for handling input and output. You've already seen some of these in the example programs throughout the book.

pinMode(pin, mode)

Reconfigures a digital pin to behave either as an input or an output.

Example:

pinMode(7,INPUT); // turns pin 7 into an input

digitalWrite(pin, value)

Turns a digital pin either on or off. Pins must be explicitly made into an output using pinMode before digitalWrite will have any effect.

Example:

digitalWrite(8,HIGH); // turns on digital pin 8

int digitalRead(pin)

Reads the state of an input pin, returns HIGH if the pin senses some voltage or LOW if there is no voltage applied.

Example:

val = digitalRead(7); // reads pin 7 into val

int analogRead(pin)

Reads the voltage applied to an analog input pin and returns a number between 0 and 1023 that represents the voltages between 0 and 5 V.

Example:

val = analogRead(0); // reads analog input 0 into val

analogWrite(pin, value)

Changes the PWM rate on one of the pins marked PWM. pin may be 11,10, 9, 6, 5, 3. value may be a number between 0 and 255 that represents the scale between 0 and 5 V output voltage.

Example:

analogWrite(9,128); // Dim an LED on pin 9 to 50%

shiftOut(dataPin, clockPin, bitOrder, value)

Sends data to a shift register, devices that are used to expand the number of digital outputs. This protocol uses one pin for data and one for clock. bitOrder indicates the ordering of bytes (least significant or most significant) and value is the actual byte to be sent out. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Getting Started with Arduino, 3rd Edition

Getting Started with Arduino, 3rd Edition

Massimo Banzi, Michael Shiloh
Mastering Arduino

Mastering Arduino

Jon Hoffman, Ejike (George Steve) Ifeanyichukwu, Pratik Desai
Arduino Cookbook

Arduino Cookbook

Michael Margolis

Publisher Resources

ISBN: 9780596155704Errata Page