This extends the previous lesson by adding a button to control the LED’s state.

the input of the button is a digital signal, and so there are only two states, 0 or 1, OFF OR ON. So it can control the output to the LED by setting it to the same state as input.

Hardware connection

For these lessons, the Components are already connected through the board. That is, for this lesson, LED module is already connected to D4 on the microprocessor.

Code Analysis

Setup

The input D6 and output D4 are automatically set to input and output. No coding needed.

Loop

IF D6 is Hi (Button is pressed)

Loop means that this part gets continuously repeated.

A short delay is added to each loop so that the microprocessor isn’t always busy doing nothing.