Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Arduino for Kids

You're reading from   Arduino for Kids A cool guide to help kids develop robots and electronics

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781785884818
Length 218 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Rishi Gaurav Bhatnagar Rishi Gaurav Bhatnagar
Author Profile Icon Rishi Gaurav Bhatnagar
Rishi Gaurav Bhatnagar
Priya Kuber Priya Kuber
Author Profile Icon Priya Kuber
Priya Kuber
Vijay Varada Vijay Varada
Author Profile Icon Vijay Varada
Vijay Varada
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. The World around Us FREE CHAPTER 2. Systems and Logic 3. Components and Connections 4. The Magic Wand 5. Hello World! 6. Safety Box 7. Make a Friend 8. Save Energy 9. High 5! 10. Plant, Meet Arduino!

The working


When the button isn't pressed, there is no connection between the two legs of the button; it will input 0V to the Arduino since the pin of the button is connected to ground through the pull-down resistor. If you recall what we learned about logic states, the Arduino should read a LOW or binary 0 in this case.

Then the button is pressed and the connection is closed; this makes a connection between its two legs, thus connecting 5V to the Arduino's I/O pin, and we read a HIGH or binary 1.

Let's walk through this code, line by line, so that you can understand what each line does:

int state = 0; 

This initializes a variable of an integer type and puts the value of 0 in it.

This is also called initializing a variable. In our case, this variable shall store the value of the state of our button. Values are assigned to variables using = ; hence, this is also called an assignment operator:

void setup() { 
  // initialize digital I/O pins 
  pinMode(2, INPUT); 
  pinMode...
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
Banner background image