-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl_3_leduri_cu_butoane
59 lines (47 loc) · 1.48 KB
/
Control_3_leduri_cu_butoane
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
import RPi.GPIO as GPIO
import time
# Configurare GPIO
GPIO.setmode(GPIO.BCM) # Utilizeaza numerotarea GPIO BCM
# Define?te pinii
BUTTON_LEFT = 17
BUTTON_RIGHT = 27
led_r = 22
led_g = 23
led_b = 24
GPIO.setup(BUTTON_LEFT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUTTON_RIGHT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(led_r, GPIO.OUT)
GPIO.setup(led_g, GPIO.OUT)
GPIO.setup(led_b, GPIO.OUT)
GPIO.output(led_r, GPIO.LOW)
GPIO.output(led_g, GPIO.LOW)
GPIO.output(led_b, GPIO.LOW)
current_led = led_r
try:
while True:
if GPIO.input(BUTTON_LEFT) == GPIO.LOW:
GPIO.output(current_led, GPIO.LOW)
if current_led == led_r:
current_led = led_b
elif current_led == led_g:
current_led = led_r
elif current_led == led_b:
current_led = led_g
GPIO.output(current_led, GPIO.HIGH)
print(f"LED-ul {current_led} aprins spre stanga")
time.sleep(0.3)
if GPIO.input(BUTTON_RIGHT) == GPIO.LOW:
GPIO.output(current_led, GPIO.LOW)
if current_led == led_r:
current_led = led_g
elif current_led == led_g:
current_led = led_b
elif current_led == led_b:
current_led = led_r
GPIO.output(current_led, GPIO.HIGH)
print(f"LED-ul {current_led} aprins spre dreapta")
time.sleep(0.3)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()