-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED.py
38 lines (29 loc) · 794 Bytes
/
LED.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import RPi.GPIO as GPIO
import time
import Tkinter as tk
GPIO.setmode(GPIO.BCM)
led = 14
GPIO.setup(led, GPIO.OUT)
def onKeyPress(event):
text.insert('end', 'You pressed %s\n' % (event.char, ))
GPIO.output(led, GPIO.HIGH)
# time.sleep(0.1)
def onKeyRelease(event):
text.insert('end', 'You released %s\n' % (event.char, ))
GPIO.output(led, GPIO.LOW)
# time.sleep(0.1)
# while True:
# print 'LED on'
# GPIO.output(led, GPIO.HIGH)
# time.sleep(1)
# print 'LED off'
# GPIO.output(led, GPIO.LOW)
# time.sleep(1)
root = tk.Tk()
root.geometry('300x200')
text = tk.Text(root, background='black', foreground='white', font=('Comic Sans MS', 12))
text.pack()
root.bind('<KeyPress>', onKeyPress)
root.bind('<KeyRelease>', onKeyRelease)
root.mainloop()
GPIO.cleanup()