Summary of Chapter 2

Transcript

Before moving on let's see what you've learned in this chapter. We've talked about different switches. You know you can use components like pushbuttons, tilt switches, magnetic switches or even self-made switches together with Arduino to control the devices you make. You know how to connect a switch like a button to Arduino and you can set the button pin to input pullup in the setup section. You used the command digitalRead to check if the button is pressed. You controlled the good old LED light with a button and you also learned to make sounds with a piezo speaker. You used the tone command to control the pitch and length of sounds. You've learned to use a super important programming structure, the if statement. You used it to make conditional parts in your program. Some things only happen if a button is pressed and something else happens when it's not. You even made an if statement with two conditions. Both of them needed to be true before the second part of the doorbell melody was played. You also had the first look at Arduino variables: how to create a variable that stores a number, how to give it different values and how to use the variable to store the status of the program. We'll be using variables a lot so you will get enough practice with them later on. And hey, I hope you had fun with the mini project of the chapter. If you made your own switch mechanism you probably got new ideas and building skills you can use later in your projects. Or - maybe you chose exercise 2 and made a speed test game. That can be a nice start for your own project as well. The code for the game was a bit advanced but you can already understand important parts of it. It's completely fine to develop the game idea further if you have the chance.

New Arduino commands, structures and concepts in this chapter

digitalRead(pin)

if statement

tone(pin, frequency, time)

INPUT_PULLUP (scroll down on the page for the explanation)

integer variables