thread_fd.py
1001 Bytes
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
from threading import Thread
import time
from RPi import GPIO
class DD(Thread):
#Constructeur
def __init__(self, pin, t_frequences, t_tps, res):
Thread.__init__(self);
self.pin = pin
self.t_frequences = t_frequences
self.t_tps = t_tps
self.res = res
def run(self):
p = GPIO.PWM(self.pin,220)
p.start(15)
p.ChangeFrequency(self.t_frequences[0])
duree = (self.t_tps[0]*1.8)/1000
time.sleep(duree)
i = 1
while(i<len(self.t_frequences)):
p.ChangeFrequency(self.t_frequences[i])
duree = (self.t_tps[i]*1.8)/1000
time.sleep(duree)
i+=1
p.stop()
GPIO.cleanup()
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)