Last active
September 11, 2023 07:49
-
-
Save lovasoa/4827b19cc7150ab878536cbf11694463 to your computer and use it in GitHub Desktop.
pompes à cocktail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import board | |
import busio | |
from adafruit_mcp230xx.mcp23017 import MCP23017 | |
import time | |
from typing import List, Tuple | |
i2c = busio.I2C(board.SCL, board.SDA) | |
mcp = MCP23017(i2c, address=0x27) | |
NOMBRE_POMPES = 16 | |
CENTILITRES_PAR_SECONDE = 450 | |
pompes = [mcp.get_pin(i) for i in range(NOMBRE_POMPES)] | |
for pompe in pompes: | |
pompe.switch_to_output(value=True) | |
def allumer_pompe(numero_pompe: int): | |
pompes[numero_pompe].value = False | |
def eteindre_pompe(numero_pompe: int): | |
pompes[numero_pompe].value = True | |
def allumer_pompe_duree(numero_pompe: int, centilitres: int): | |
allumer_pompe(numero_pompe) | |
time.sleep(centilitres / CENTILITRES_PAR_SECONDE) | |
eteindre_pompe(numero_pompe) | |
def faire_cocktail(ingredients: List[Tuple[int, int]]): | |
"""Fait un cocktail avec les ingrédients donnés. | |
ingredients est une liste de tuples (pompe, duree) où pompe est le numéro de la pompe et duree est la durée en centilitres. | |
Par exemple, pour faire un cocktail avec 10cl de pompe 0 et 15cl de pompe 1: | |
>>> faire_cocktail([(0, 10), (1, 15)]) | |
""" | |
for (pompe, duree) in ingredients: | |
allumer_pompe_duree(pompe, duree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment