. Today we try to read in digital values. At the connections., The task is very simple.. An LED is to be switched on and off with two buttons. Lets. Look at the circuit construction first., The LED with the series resistor is again at connection 2.. The two buttons are connected to connections 3 and 4.. As soon as the button is pressed, the input is connected to the operating voltage. That corresponds to high potential., So that the input is not open. When the button is not pressed and perhaps has an undefined status, it is connected to ground via the 10k resistor, i.e. low level.. So our program has to react as soon as an input gets high potential. To ensure that parts of the program are only executed under a specific condition. We need the conditional statement if. If the condition in the round brackets is fulfilled, then the program code in the curly brackets is executed. If the condition is not met. This part is simply skipped.. If we want alternative program code to be executed, if the condition is not met, we extend the statement with an else block.. So if the condition is met, the upper part is processed. Otherwise, the lower part. Now lets go into our program. In the setup part. Of course, we first define our assigned connections. Port 2 works as an output. Again. Port 3 is the first button works as an input. And at connection 4. We have the second button, the off switch.

. It also works as an entrance.. It makes sense to program a defined initial state.. I want the LED to be off after switching on, so we apply low potential to connection 2. In the loop part. We first ask what the status is at input 3. This happens with the digitalRead statement.. The connection number comes in brackets.. We ask whether this connection has high potential.. The fact that there are two equal signs is not a typo, because this is a relational operator.. When we assign a value to a variable. We use the simple equals sign.. When we compare two values, we use the double equals sign, which means exactly the same.. Of course, we can also compare whether the value is smaller or larger, smaller or equal or larger or equal., And the exclamation mark before the equal sign means not equal.. So if button 1 is pressed at Port 3, then we want to switch on the LED and apply high potential to connection 2.. With the button on 4, we want to switch the LED off again., So we now query connection 4.. When the button is pressed, we apply low potential to connection 2 again. And now all we have to do is try it. Out. Left button LED on. Right button, LED off.. Everything seems to work. Thats it for part 7..