-
Notifications
You must be signed in to change notification settings - Fork 2
/
pwm.py
60 lines (47 loc) · 1.31 KB
/
pwm.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
import RPi.GPIO as GPIO
from time import sleep
import socket
print("Program Started..")
GPIO.setmode(GPIO.BCM)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(14, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
right = GPIO.PWM(14, 100)
mid = GPIO.PWM(15, 100)
left = GPIO.PWM(18, 100)
left.start(100)
mid.start(100)
right.start(100)
pause_time = 0.02
ip = ""
port = 8888
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((ip, port))
try:
while True:
data, addr = sock.recvfrom(1024)
print("Receiving Message: {}".format(data.decode()))
name = data.decode()
if name == "No_Detection":
en_sol.start(100)
orta.start(100)
en_sag.start(100)
print("There is No Detection")
if name == "first_pwm":
en_sol.start(20)
sleep(pause_time)
print("Left Headlight Going Down")
if name == "second_pwm":
orta.start(20)
sleep(pause_time)
print("Middle Headlight Going Down")
if name == "third_pwm":
en_sag.start(20)
sleep(pause_time)
print("Right Headlight Going Down")
except KeyboardInterrupt:
GPIO.cleanup()
en_sag.stop()
orta.stop()
en_sol.stop()
GPIO.cleanup()