User manual
78
Fig. 10.1: A single LED at GPIO port 4.
Connect an LED via a series resistor to the GPIO port 4. The programme ledtk01.py will turn the lights on.
import RPi.GPIO as GPIO
from Tkinter import *
LED = 4; GPIO.setmode(GPIO.BCM); GPIO.setup(LED,GPIO.OUT)
def LedOn():
GPIO.output(LED,True)
def LedOff():
GPIO.output(LED,True)
root = Tk(); root.title("LED")
Label(root,
text=”Please click a button to turn the LED on
or off").pack()
Button(root, text=”On", command=LedOn).pack(side=LEFT)