-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblink_LED.py
85 lines (67 loc) · 2.04 KB
/
blink_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
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
import RPi.GPIO as GPIO
import time
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function
pinLED = 17 # LED GPIO Pin
GPIO.setmode(GPIO.BCM) # Use GPIO pin number
GPIO.setwarnings(False) # Ignore warnings in our case
GPIO.setup(pinLED, GPIO.OUT) # GPIO pin as output pin
s = 1
class LED_class:
def parseData(self, child_conn):
try:
while True:
s = 0
while child_conn.poll():
s = child_conn.recv()
print(s)
while s == 1:
GPIO.output(pinLED, GPIO.HIGH) # Turn on
sleep(0.3) # Pause 1 second
GPIO.output(pinLED, GPIO.LOW) # Turn off
sleep(0.3) # Pause 1 second
if child_conn.poll():
print("Received")
s = 0
GPIO.output(pinLED, GPIO.LOW)
break
finally:
GPIO.output(pinLED, GPIO.HIGH)
GPIO.cleanup()
# Set the GPIO mode and PWM frequency
GPIO.setmode(GPIO.BCM)
PWM_FREQUENCY = 1000
# Pin numbers for Red, Green, and Blue channels
RED_PIN = 17
GREEN_PIN = 18
BLUE_PIN = 27
# Setup PWM channels for Red, Green, and Blue LEDs
GPIO.setup(RED_PIN, GPIO.OUT)
GPIO.setup(GREEN_PIN, GPIO.OUT)
GPIO.setup(BLUE_PIN, GPIO.OUT)
red_pwm = GPIO.PWM(RED_PIN, PWM_FREQUENCY)
green_pwm = GPIO.PWM(GREEN_PIN, PWM_FREQUENCY)
blue_pwm = GPIO.PWM(BLUE_PIN, PWM_FREQUENCY)
red_pwm.start(0)
green_pwm.start(0)
blue_pwm.start(0)
def error_call():
red_pwm.ChangeDutyCycle(95)
green_pwm.ChangeDutyCycle(0)
blue_pwm.ChangeDutyCycle(0)
def recording():
green_pwm.ChangeDutyCycle(95)
blue_pwm.ChangeDutyCycle(0)
red_pwm.ChangeDutyCycle(0)
def speaking():
blue_pwm.ChangeDutyCycle(95)
green_pwm.ChangeDutyCycle(0)
red_pwm.ChangeDutyCycle(0)
a = int(input("choice"))
if a == 1:
error_call()
GPIO.cleanup()
elif a == 2:
recording()
else:
speaking()