-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRPI_GUI.py
94 lines (73 loc) · 2.19 KB
/
RPI_GUI.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from tkinter import *
from tkinter import font
from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
from time import time, sleep
import RPi.GPIO as GPIO
led = 13 # GPIO 27 = pin 13
piezo = 7 # GPIO 04 = pin 7
PORT_NUMBER = 5000
SIZE = 1024
# Set up GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
pin7 = GPIO.PWM(7, 100)
pin7.start(50)
GPIO.setup(led, GPIO.OUT)
start = time()
current = time()
String = ""
Read = ""
is_beeping = False
GPIO.output(7, GPIO.LOW)
pin7.ChangeFrequency(0.1)
def Beep():
global current
global start
global is_beeping
dif = int(current - start)
if (dif < 0.2) and not is_beeping:
GPIO.output(led, GPIO.HIGH)
GPIO.output(7, GPIO.HIGH)
pin7.ChangeFrequency(400) # A4
is_beeping = True
sleep(0.1) # Beep for 0.1 seconds
GPIO.output(led, GPIO.LOW)
GPIO.output(7, GPIO.LOW)
pin7.ChangeFrequency(0.1)
is_beeping = False
def receive_data():
global String
global Read
data, addr = mySocket.recvfrom(SIZE)
print(data)
if len(data) > 1:
String = data
start = time()
Beep() # Beep when String is updated
else:
if data == "~":
String = ""
elif data == "<":
String = String[:-1]
Read = data
Beep()
confirmed_letter.delete("1.0", END)
confirmed_letter.insert(END, Read)
confirmed_letter.tag_add("center", "1.0", "end")
status_bar1.config(text=String)
app.after(100, receive_data)
hostName = gethostbyname('0.0.0.0')
mySocket = socket(AF_INET, SOCK_DGRAM)
mySocket.bind((hostName, PORT_NUMBER))
app = Tk()
app.bind('<Escape>', lambda e: app.quit())
customFont_2 = font.Font(family='Arial', size=25)
status_bar1 = Label(app, bd=1, relief=SUNKEN, anchor=W, height=2, font=customFont_2)
status_bar1.grid(row=2, column=0, columnspan=2, sticky=E+W)
customFont = font.Font(family='Arial', size=100)
confirmed_letter = Text(app, bd=1, relief=SUNKEN, height=1, width=2, font=customFont)
confirmed_letter.grid(row=0, column=1, padx=10, pady=10, sticky=NE)
confirmed_letter.tag_configure("center", justify='center')
app.after(100, receive_data)
app.mainloop()