Skip to content
Snippets Groups Projects
Commit 505c799a authored by TERRU Theo's avatar TERRU Theo
Browse files

V1 script final 3 lignes

parent 6ae8d0f9
No related branches found
No related tags found
1 merge request!1MAJ BDD + Data commande fonctionnel
......@@ -4,6 +4,7 @@ from time import sleep # this lets us have a time delay (see line 12)
import sys
increment = 0
nbrBoucle = 0
stop = 0
args = []
......@@ -25,7 +26,7 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
# Setup des composants
GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering
GPIO.setup(25, GPIO.IN) # DEBITMETRE
GPIO.setup(25, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # DEBITMETRE
GPIO.setup(24, GPIO.OUT, initial=GPIO.LOW) # ELECTROVANNE 1
GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW) # ELECTROVANNE 2
GPIO.setup(23, GPIO.OUT) # POMPE
......@@ -33,13 +34,20 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
global increment
global stop
Q = int(quantite / 5)
q = int(quantite % 5)
print("Q =", Q)
print("q =", q)
# Define a threaded callback function to run in another thread when events are detected
def my_callback(channel):
global increment
global stop
global nbrBoucle
# Si la quantité désirée a été pompée
if increment == quantite and not stop:
if nbrBoucle == Q-1 and not stop:
# Arrêt de tous les composants
......@@ -61,13 +69,7 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
print(increment)
# Ajout du callback débitmètre
GPIO.add_event_detect(25, GPIO.BOTH, callback=my_callback)
# Démarrage des composants requis
if args[Pompe1]:
p.start(80)
print("Pompe1 ouverte")
#GPIO.output(23, GPIO.HIGH)
GPIO.add_event_detect(25, GPIO.RISING, callback=my_callback, bouncetime=5)
if args[EV1]:
GPIO.output(24, GPIO.HIGH)
......@@ -77,6 +79,27 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
GPIO.output(21, GPIO.HIGH)
print("Electrovanne2 ouverte")
# Démarrage des composants requis
if args[Pompe1]:
global nbrBoucle
print("Pompe1 ouverte")
for i in range(Q):
PWM = 0
increment = 1
while PWM <= 50:
p.start(PWM)
print("PWM =", PWM)
PWM += 5
sleep(0.1)
while increment % 5 != 0:
pass
increment = 1
p.stop()
nbrBoucle+=1
#sleep(0.3)
#GPIO.output(23, GPIO.HIGH)
try:
# Thread du débitmètre tourne en fond
while not stop:
......@@ -101,5 +124,5 @@ if __name__=="__main__":
args.append(int(strParam))
except ValueError:
print( "Bad parameter value: %s" % strParam, file=sys.stderr )
testDebimetre(2, 5)
testDebimetre(2, 28)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment