-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphone.py
More file actions
69 lines (59 loc) · 1.83 KB
/
phone.py
File metadata and controls
69 lines (59 loc) · 1.83 KB
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
print("Hello world!")
from time import sleep
import math
from gpiozero import Button, LED
import vlc
dialling = Button(17) # brown
dial_pulser = Button(27) # orange
off_hook = Button(22) # yellow
indicator = LED(23)
num_dialled = ''
button_state = False
counter = 0
playing = False
ringing = vlc.MediaPlayer("file:///home/sarbin/Documents/electronics/ringing.mp3")
success = vlc.MediaPlayer("file:///home/sarbin/Documents/electronics/dialup.mp3")
while True:
if off_hook.is_pressed:
if not playing:
ringing.play()
playing = True
else:
ringing.stop()
playing = False
if dialling.is_pressed:
if dial_pulser.is_pressed:
indicator.on()
if button_state:
# Was on, stay on
pass
else:
# Was off, now on
print("Yes on!")
counter += 1
button_state = True
else:
indicator.off()
if button_state:
# Was on, now off
print("Now off!")
pass
else:
# Was off, stay off
pass
button_state = False
else:
if counter > 0:
print("Adding number to what dialled:")
print(counter)
num_dialled += str(counter % 10)
print("Brings us up to:")
print(num_dialled)
counter = 0
if len(num_dialled) == 3:
if num_dialled == '123':
print("That's correct!")
success.play()
else:
print("Nope, wrong")
num_dialled = ''