Reader small image

You're reading from  Arduino for Kids

Product typeBook
Published inMar 2017
PublisherPackt
ISBN-139781785884818
Edition1st Edition
Tools
Concepts
Right arrow
Authors (2):
Rishi Gaurav Bhatnagar
Rishi Gaurav Bhatnagar
author image
Rishi Gaurav Bhatnagar

Rishi Gaurav Bhatnagar is a creative technologist who likes to work at the intersection of design and technology. He is an Intel software innovator, Arduino maker fellow, a volunteer at Random Hacks Of Kindness, also Campus Diaries 25 under 25- Science & Tech. When he is not tinkering with technology and storytelling, he spends time building new modules for students that help fuel their curiosity and build their innovation muscle.
Read more about Rishi Gaurav Bhatnagar

Vijay Varada
Vijay Varada
author image
Vijay Varada

Vijay Varada is an artist, engineer, and entrepreneur whose motto is, create positive change in the world through art, design and technology for sustainable and exponential development and progress. He is the CEO, and cofounder of Fracktal Works, which is engaged with design and research in the field of additive manufacturing, rapid prototyping, and product design with its line of desktop and industrial 3D printers aimed at using the technology to empower the abilities of students, engineers, designers, and industries. Vijay actively contributes to open source hardware projects, particularly assistive technologies for the blind.
Read more about Vijay Varada

View More author details
Right arrow

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 page is locked
Previous PageNext Page
You have been reading a chapter from
Arduino for Kids
Published in: Mar 2017Publisher: PacktISBN-13: 9781785884818

Authors (2)

author image
Rishi Gaurav Bhatnagar

Rishi Gaurav Bhatnagar is a creative technologist who likes to work at the intersection of design and technology. He is an Intel software innovator, Arduino maker fellow, a volunteer at Random Hacks Of Kindness, also Campus Diaries 25 under 25- Science & Tech. When he is not tinkering with technology and storytelling, he spends time building new modules for students that help fuel their curiosity and build their innovation muscle.
Read more about Rishi Gaurav Bhatnagar

author image
Vijay Varada

Vijay Varada is an artist, engineer, and entrepreneur whose motto is, create positive change in the world through art, design and technology for sustainable and exponential development and progress. He is the CEO, and cofounder of Fracktal Works, which is engaged with design and research in the field of additive manufacturing, rapid prototyping, and product design with its line of desktop and industrial 3D printers aimed at using the technology to empower the abilities of students, engineers, designers, and industries. Vijay actively contributes to open source hardware projects, particularly assistive technologies for the blind.
Read more about Vijay Varada