thread_dd.py
1.12 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
from threading import Thread
import time
from RPi import GPIO
class DD(Thread):
#Constructeur
def __init__(self, pin, t_notes, t_tps):
Thread.__init__(self);
self.pin = pin
self.t_notes = t_notes
self.t_tps = t_tps
def run(self):
p = GPIO.PWM(self.pin,220)
p.start(15)
i = 0
while(i<len(self.t_notes)-1):
p.ChangeFrequency(self.t_notes[i])
time.sleep(self.t_tps[i])
i+=1
GPIO.cleanup()
notes=[220,1,220,1,220,1,174.5,1,261.5,1,220,1,174.5,1,261.5,1,220,1]
tps = [1,0.02,1,0.02,1,0.02,0.4,0.05,0.6,0.05,0.4,0.05,0.6,0.05,0.4,0.05,0.6,0.05]
GPIO.setmode(GPIO.BCM)
#DD1
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(25,GPIO.OUT)
#DD2
GPIO.setup(16,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
#PWM
GPIO.setup(18,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
#Act DD1
GPIO.output(23,GPIO.LOW)
GPIO.output(24,GPIO.LOW)
GPIO.output(25,GPIO.LOW)
#Act DD2
GPIO.output(16,GPIO.LOW)
GPIO.output(20,GPIO.LOW)
GPIO.output(21,GPIO.LOW)
#Creation des threads
thread1 = DD(18,notes,tps)
thread2 = DD(13,notes,tps)
#Lancement des threads
thread1.start()
thread2.start()
#Synchro
thread1.join()
thread2.join()