User Guide
Table Of Contents
164
example, sleep(2). If you want to blink the LED faster, decrease
the value that you pass into sleep(). For example, sleep(0.5).
You cannot run this script from IDLE3, because controlling the
GPIO pins requires superuser access. To run your script:
1. On the Application Launcher, click LXTerminal.
2. Browse to your script. For example, if you saved the
file as test.py on the desktop:
cd Desktop
3. Type the following command and then press Enter.
Change test.py to the name of your script.
sudo python3 test.py
The LED will now blink on and off. Because the while loop in this
script never receives False, the script runs forever. To stop the
script, press Ctrl + C.
7.5 Basic Input
With the GPIO pins, input involves finding out whether the
voltage that is coming into a pin from your external circuit is
high, or whether it is low. In this section, you will see how to
detect when a switch is closed. Any switch will work for this, but
two-terminal on/off switches and four-terminal tactile push
buttons are the ones that people use most often.
With four-terminal push buttons, it can be difficult to see which
way round in the circuit you should place them. The top-left and
top-right terminals are always joined. The top-left and bottom-
left terminals are only joined when the switch is pressed. So if
your circuit always detects that the switch is pressed, rotate the
button 90° in a clockwise direction.
Do not wire a switch on its own between the 3.3 V power-output
pin and a GPIO input. When the switch is pressed, 3.3 V flows
into the input pin and brings the input high. But there are two
potential problems with this: