from machine import Pin, I2C
from time import sleep_ms
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
# ----Sortie LED----------------------------------------------
led_rouge = Pin(18, Pin.OUT)
led_vert = Pin(19, Pin.OUT)
led_jaune = Pin(20, Pin.OUT)
# ----Entrée Bouton----------------------------------------------
button_rouge = Pin(13, Pin.IN, Pin.PULL_UP)
button_vert = Pin(12, Pin.IN, Pin.PULL_UP)
button_jaune = Pin(11, Pin.IN, Pin.PULL_UP)
# ----Sorties Ecran LCD----------------------------------------------
I2C_ADDR = 39 # adresse I2C
I2C_NUM_ROWS = 2 # nombre de lignes
I2C_NUM_COLS = 16 # nombre de colonnes
i2c = I2C(1, sda=Pin(2, Pin.OUT), scl=Pin(3, Pin.OUT), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
# ----CREATION de fonctions----------------------------------------------
def eteindre_ecran():
lcd.backlight_off()
print("éteindre_ecran()")
def allumer_ecran():
lcd.backlight_on()
print("allumer_ecran()")
def clear_ecran():
lcd.clear()
print("clear_ecran()")
# -----Conditions initiales---------------------------------------------
# ----LED éteintes---------------------------------------------
led_rouge.value(0)
led_vert.value(0)
led_jaune.value(0)
# ----Ecran LCD---------------------------------------------
allumer_ecran()
clear_ecran()
# ----Début du programme----------------------------------------------
print(i2c.scan()) # scanner un bus I2C et renvoyer une liste d'adresses I2C valides qui sont connectées à ce bus
while True:
if button_vert.value() == 0:
allumer_ecran()
led_vert.value(1)
clear_ecran()
lcd.putstr("machine en marche")
else:
led_vert.value(0)
if button_rouge.value() == 0:
allumer_ecran()
led_rouge.value(1)
clear_ecran()
lcd.putstr("machine en panne")
else:
led_rouge.value(0)
if button_jaune.value() == 0:
allumer_ecran()
led_jaune.value(1)
clear_ecran()
lcd.putstr("machine en cours d'intervention")
else:
led_jaune.value(0)