Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Arduino Essentials

You're reading from   Arduino Essentials Enter the world of Arduino and its peripherals and start creating interesting projects

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher Packt
ISBN-13 9781784398569
Length 206 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Meeting the Arduino Family 2. The Arduino Development Environment FREE CHAPTER 3. Interacting with the Environment the Digital Way 4. Controlling Outputs Softly with Analog Outputs 5. Sensing the Real World through Digital Inputs 6. Analog Inputs to Feel Between All and Nothing 7. Managing the Time Domain 8. Communicating with Others 9. Dealing with Interrupts 10. Arduino in a Real Case – Greenhouse Control Index

Writing code to react to a press


Before we go into the details of the programming of such a circuit, we'll have to decide what behavior we will unchain in our project once the event of a press is detected. For the sake of simplicity, we will make an LED blink or fade depending on the press of the button.

This way, we can test all that we have already learned in a simple example and this will also lead us to meet another very important control structure of any programming language, called a conditional bifurcation, which some say is the basic structure that makes any program a logical structure and not a simple sequence of instructions.

Once the circuit is assembled, let's take a look at the code we are going to write to detect and react to the button press as a digital input. Here, you have the complete code for this example:

/*
 Chapter 05 - Sensing the real world through digital inputs
 Sensing a switch
 By Francis Perea for Packt Publishing
*/

// Global variables we will use
int led = 9...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime