I am sure you remember this line of code from the previous chapter:
GPIO.setup(18,GPIO.OUT)
As explained earlier, this basically tells us how GPIO the pin will behave in a certain program. By now, you must have guessed that by changing this single line of code we can change the behavior of the pin and convert it from output to input. This is how you would do it:
GPIO.setup(18,GPIO.IN)
Once you write this line of code in your program, the microcontroller will know that during the time that the program is being run, the pin number 18 will only be used for input purposes.Â
To understand how this would actually work, let's head back to our hardware and see how it can be done. Firstly, you need to connect an LED to any of the pins; we will be using pin number 23 in this program. Secondly, you need to connect a switch on pin number 24. You can refer...