Before writing a Python program to use the switch, you can try some experiments from the Python console.

To launch the Python Console type:
# python
Python 2.7.3 (default, Apr  3 2013, 21:37:23) 
[GCC 4.7.3 20130205 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
If you are using Ubuntu or Debian, you may need to launch python with 'sudo python' to use GPIO.
First, we need to import the library, so enter the command:
>>> import Adafruit_BBIO.GPIO as GPIO
Let's now set the pin we are going to use to be an input:
>>> GPIO.setup("P8_12", GPIO.IN)
At this point, do not press the switch, but type:
>>> GPIO.input("P8_12")
Now hold down the push switch and run the Python line again, by pressing the up cursor key and RETURN.
>>> GPIO.input("P8_12")

So, this experiment has shown us that when the key is pressed, requesting the input value from the pin will have a value of 1 and when it is not pressed, it will be 0.

This guide was first published on Jul 30, 2013. It was last updated on Jul 30, 2013.

This page (The Python Console) was last updated on Jul 30, 2013.

Text editor powered by tinymce.