Commit a0b18c1414ab1d4645d4201a426258af072c5199

Authored by troj
1 parent 897e83d9

Commit rasp

Showing 1 changed file with 58 additions and 0 deletions   Show diff stats
thread_dd.py 0 → 100644
@@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
  1 +from threading import Thread
  2 +import time
  3 +from RPi import GPIO
  4 +
  5 +class DD(Thread):
  6 +
  7 + #Constructeur
  8 + def __init__(self, pin, t_notes, t_tps):
  9 + Thread.__init__(self);
  10 + self.pin = pin
  11 + self.t_notes = t_notes
  12 + self.t_tps = t_tps
  13 +
  14 + def run(self):
  15 + p = GPIO.PWM(self.pin,220)
  16 + p.start(15)
  17 + i = 0
  18 + while(i<len(self.t_notes)-1):
  19 + p.ChangeFrequency(self.t_notes[i])
  20 + time.sleep(self.t_tps[i])
  21 + i+=1
  22 + GPIO.cleanup()
  23 +
  24 +notes=[220,1,220,1,220,1,174.5,1,261.5,1,220,1,174.5,1,261.5,1,220,1]
  25 +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]
  26 +
  27 +GPIO.setmode(GPIO.BCM)
  28 +#DD1
  29 +GPIO.setup(23,GPIO.OUT)
  30 +GPIO.setup(24,GPIO.OUT)
  31 +GPIO.setup(25,GPIO.OUT)
  32 +#DD2
  33 +GPIO.setup(16,GPIO.OUT)
  34 +GPIO.setup(20,GPIO.OUT)
  35 +GPIO.setup(21,GPIO.OUT)
  36 +#PWM
  37 +GPIO.setup(18,GPIO.OUT)
  38 +GPIO.setup(13,GPIO.OUT)
  39 +#Act DD1
  40 +GPIO.output(23,GPIO.LOW)
  41 +GPIO.output(24,GPIO.LOW)
  42 +GPIO.output(25,GPIO.LOW)
  43 +#Act DD2
  44 +GPIO.output(16,GPIO.LOW)
  45 +GPIO.output(20,GPIO.LOW)
  46 +GPIO.output(21,GPIO.LOW)
  47 +
  48 +#Creation des threads
  49 +thread1 = DD(18,notes,tps)
  50 +thread2 = DD(13,notes,tps)
  51 +
  52 +#Lancement des threads
  53 +thread1.start()
  54 +thread2.start()
  55 +
  56 +#Synchro
  57 +thread1.join()
  58 +thread2.join()