import tm1637
from machine import Pin,SoftI2C,I2C
import ssd1306
import time
from lcdi2c import LCDI2C
import dht
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
import utime
from picozero import RGBLED
from neopixel import Neopixel
I2C_ADDR = 0x27
I2C_NUM_ROWS = 4
I2C_NUM_COLS = 20
i2c = SoftI2C(scl=Pin(5), sda=Pin(4))
# Crée un objet I2C
i2c0 = I2C(1, scl=Pin(11), sda=Pin(10), freq=400000) # I2C0 utilisé
lcd = I2cLcd(i2c0, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
lcd.putstr("Helllooo The Bin")
sensor = dht.DHT22(Pin(13))
sensor.measure()
print('INIT Bin project :')
print(str(sensor.temperature()) + "°C")
print(str(sensor.humidity())+"%")
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
tm = tm1637.TM1637(clk=Pin(0), dio=Pin(1))
tm.brightness(5)
mvdetect = Pin(9, Pin.IN, Pin.PULL_UP)
rled = RGBLED(blue=19, red=21, green=20)
buzz = Pin(28, Pin.OUT)
numdetect = 0
while True:
lcd.clear()
ltime = utime.localtime()
lcd.move_to(0,0)
lcd.putstr("{year:>04d}/{month:>02d}/{day:>02d}".format(
year=ltime[0], month=ltime[1], day=ltime[2]
)
)
lcd.move_to(0,1)
lcd.putstr("{HH:>02d}:{MM:>02d}:{SS:>02d}".format(HH=ltime[3], MM=ltime[4], SS=ltime[5]))
oled.fill(0)
oled.text('Nombre de detect', 0, 0)
a = str(numdetect)
oled.text(f' {a} fois',0,10)
oled.show()
if mvdetect.value() == 0:
print("No detect")
rled.color = (0, 0, 255)
tm.scroll('NOTHING',delay=250)
time.sleep(3)
else:
rled.color = (255, 0, 0)
tm.show("OOOO",colon=False)
time.sleep(0.4)
tm.show("ccc",colon=False)
time.sleep(0.4)
tm.show("OOOO",colon=False)
buzz.high()
numdetect += 1
print("detect")
oled.fill(0)
oled.text('ATTENTION', 0, 0)
oled.text('Detection', 0, 10)
oled.show()
time.sleep(1)
buzz.low()
time.sleep(1)