The button and the question “if”
Section 3: Inputs: the buttonLesson 3.1 · ⏱ 8 min
Until now the Arduino has only talked. Now it will listen: the button is an input. We ask: “Is the button pressed?”, and choose what to do with if … else.

🖥️ What happens on the stage?
As long as you press the button, the LED is on, and when you let go it goes off.
📌 Another example: the opposite: the button turns it off
The LED is always on, and when you press the button it goes off.



✍️ Practise
Build the button and the LED.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
As long as you press, the LED blinks.
👀 Show the solution🙈 Hide the solution


Result: it blinks while you press.
Medium
Press once: it lights for 3 seconds, then goes off by itself (a stairway light).
👀 Show the solution🙈 Hide the solution


Result: it stays on 3 seconds after you let go, then goes off.
Hard
Press once: it lights up and stays on (there is no “else”).
👀 Show the solution🙈 Hide the solution


Result: it stays on after you let go.

