Reader small image

You're reading from  Python Robotics Projects

Product typeBook
Published inMay 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788832922
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Prof. Diwakar Vaish
Prof. Diwakar Vaish
author image
Prof. Diwakar Vaish

Prof. Diwakar Vaish is a robotics scientist and the inventor of Manav (India's first indigenous humanoid robot), the world's first mind-controlled wheelchair, brain cloning, and the world's cheapest ventilator. He has also been a guest lecturer at over 13 IITs and various other institutions. He is the founder of A-SET Robotics, a leading robotics research company based in New Delhi.
Read more about Prof. Diwakar Vaish

Right arrow

A deeper dive into GPIOs


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 the diagram that follows for making the connections:

Once you connect it, you can go ahead and write this program:

import time import...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Python Robotics Projects
Published in: May 2018Publisher: PacktISBN-13: 9781788832922

Author (1)

author image
Prof. Diwakar Vaish

Prof. Diwakar Vaish is a robotics scientist and the inventor of Manav (India's first indigenous humanoid robot), the world's first mind-controlled wheelchair, brain cloning, and the world's cheapest ventilator. He has also been a guest lecturer at over 13 IITs and various other institutions. He is the founder of A-SET Robotics, a leading robotics research company based in New Delhi.
Read more about Prof. Diwakar Vaish