Skip to content

Commit 31b8c98

Browse files
final
1 parent aed7aee commit 31b8c98

7 files changed

Lines changed: 159 additions & 27 deletions

File tree

project/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
sleep(0.1)
88

99
# File name of the script to import
10-
file_name = "v03"
10+
file_name = "v02"
1111

1212
# Add the path to the sys.path
1313
sys.path.append("/py_scripts")

project/py_scripts/v13.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Lecture 4 - Completed Pedestrian_Button Implementation
3+
"""
4+
5+
from pedestrian_button import Pedestrian_Button
6+
import time
7+
8+
# Create a Pedestrian_Button on GPIO pin 14 with debug enabled
9+
button = Pedestrian_Button(22, debug=True)
10+
11+
while True:
12+
# Check if the button has been pressed (pedestrian waiting)
13+
if button.button_state:
14+
print("Pedestrian button pressed!")
15+
# Reset the waiting state after handling
16+
button.button_state = False
17+
time.sleep(0.1)

project/py_scripts/v14.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Lecture 4 - Completed Audio_Notification Implementation
3+
"""
4+
5+
from audio_notification import Audio_Notification
6+
import time
7+
8+
# Create an Audio_Notification on GPIO pin 15 with debug enabled
9+
buzzer = Audio_Notification(27, debug=True)
10+
11+
while True:
12+
# Sound a warning beep (non-blocking, call repeatedly in your loop)
13+
buzzer.warning_on()

project/py_scripts/v15.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"""
2+
Lecture 5 - Association & Controller States
3+
"""
4+
5+
from led_light import Led_Light
6+
from pedestrian_button import Pedestrian_Button
7+
from audio_notification import Audio_Notification
8+
from time import sleep, time
9+
10+
11+
class Controller:
12+
def __init__(
13+
self, ped_red, ped_green, car_red, car_amber, car_green, button, buzzer, debug
14+
):
15+
self.__Ped_Red = ped_red
16+
self.__Ped_Green = ped_green
17+
self.__Car_Red = car_red
18+
self.__Car_Amber = car_amber
19+
self.__Car_Green = car_green
20+
self.__Buzzer = buzzer
21+
self.__Button = button
22+
self.__debug = debug
23+
24+
def walk_on(self):
25+
if self.__debug:
26+
print("Walking")
27+
self.__Ped_Red.off()
28+
self.__Ped_Green.on()
29+
self.__Car_Green.off()
30+
self.__Car_Amber.off()
31+
self.__Car_Red.on()
32+
self.__Buzzer.warning_on()
33+
34+
def walk_warning(self):
35+
if self.__debug:
36+
print("No Walking Warning")
37+
self.__Ped_Red.flash()
38+
self.__Ped_Green.off()
39+
self.__Car_Green.off()
40+
self.__Car_Amber.off()
41+
self.__Car_Red.on()
42+
self.__Buzzer.warning_off()
43+
44+
def walk_off(self):
45+
if self.__debug:
46+
print("No Walking")
47+
self.__Ped_Red.on()
48+
self.__Ped_Green.off()
49+
self.__Car_Green.on()
50+
self.__Car_Amber.off()
51+
self.__Car_Red.off()
52+
self.__Ped_Green.off()
53+
self.__Buzzer.warning_off()
54+
55+
def change(self):
56+
if self.__debug:
57+
print("Changing")
58+
self.__Ped_Red.on()
59+
self.__Ped_Green.off()
60+
self.__Car_Green.off()
61+
self.__Car_Amber.on()
62+
self.__Car_Red.off()
63+
self.__Ped_Green.off()
64+
self.__Buzzer.warning_off()
65+
66+
67+
debug = False
68+
69+
led_pedestrian_red = Led_Light(19, True, debug)
70+
led_pedestrian_green = Led_Light(17, False, debug)
71+
led_car_red = Led_Light(3, False, debug)
72+
led_car_orange = Led_Light(5, False, debug)
73+
led_car_green = Led_Light(6, False, debug)
74+
75+
pedestrian_button = Pedestrian_Button(22, debug)
76+
77+
buzzer = Audio_Notification(27, debug)
78+
79+
controller = Controller(
80+
led_pedestrian_red,
81+
led_pedestrian_green,
82+
led_car_red,
83+
led_car_orange,
84+
led_car_green,
85+
pedestrian_button,
86+
buzzer,
87+
True,
88+
)
89+
90+
while True:
91+
controller.walk_off()
92+
sleep(3)
93+
controller.change()
94+
sleep(3)
95+
controller.walk_on()
96+
sleep(3)
97+
controller.walk_warning()
98+
sleep(3)

project/py_scripts/v99.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Lecture 6 - Completed system with state machine
3+
"""
4+
15
from led_light import Led_Light
26
from pedestrian_button import Pedestrian_Button
37
from audio_notification import Audio_Notification

tutorials/Lecture4.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from pedestrian_button import Pedestrian_Button
2424
import time
2525

2626
# Create a Pedestrian_Button on GPIO pin 14 with debug enabled
27-
button = Pedestrian_Button(14, debug=True)
27+
button = Pedestrian_Button(22, debug=True)
2828

2929
while True:
3030
# Check if the button has been pressed (pedestrian waiting)
@@ -115,7 +115,7 @@ from audio_notification import Audio_Notification
115115
import time
116116

117117
# Create an Audio_Notification on GPIO pin 15 with debug enabled
118-
buzzer = Audio_Notification(15, debug=True)
118+
buzzer = Audio_Notification(27, debug=True)
119119

120120
# Sound a warning beep (non-blocking, call repeatedly in your loop)
121121
buzzer.warning_on()

tutorials/Lecture5.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,31 +119,10 @@ classDiagram
119119
Audio_Notification --> Controller: Association
120120
```
121121

122-
```python
123-
# Alternative association method
124-
class Walk_Light:
125-
def __init__(self, led_pin, buz_pin, debug):
126-
self.LED = Led_Light(led_pin, debug)
127-
self.BUZ = Audio_Notification(buz_pin, debug)
128-
self.__debug = debug
129-
130-
def walk_on(self):
131-
if self.__debug:
132-
print("Beep and Light on")
133-
self.LED.on()
134-
self.BUZ.warning_on()
135-
136-
def walk_off(self):
137-
if self.__debug:
138-
print("Beep and Light off")
139-
self.LED.off()
140-
self.BUZ.warning_off()
141-
```
142-
143-
### Setup differnet states of the controller
122+
### Setup differnet states of the controller using association
144123

145124
```python
146-
from led_light import Led_Light
125+
from led_light import Led_Light
147126
from pedestrian_button import Pedestrian_Button
148127
from audio_notification import Audio_Notification
149128
from time import sleep, time
@@ -203,4 +182,25 @@ class Controller:
203182
self.__Car_Red.off()
204183
self.__Ped_Green.off()
205184
self.__Buzzer.warning_off()
206-
```
185+
```
186+
187+
```python
188+
# Alternative association method
189+
class Walk_Light:
190+
def __init__(self, led_pin, buz_pin, debug):
191+
self.LED = Led_Light(led_pin, debug)
192+
self.BUZ = Audio_Notification(buz_pin, debug)
193+
self.__debug = debug
194+
195+
def walk_on(self):
196+
if self.__debug:
197+
print("Beep and Light on")
198+
self.LED.on()
199+
self.BUZ.warning_on()
200+
201+
def walk_off(self):
202+
if self.__debug:
203+
print("Beep and Light off")
204+
self.LED.off()
205+
self.BUZ.warning_off()
206+
```

0 commit comments

Comments
 (0)