from machine import Pin ,SoftI2C,ADC
import time
import dht
from ssd1306 import SSD1306_I2C
i2c = SoftI2C(scl=Pin(22),sda=Pin(21),freq=400000)
width , height = 128 , 64
oled = SSD1306_I2C(width , height , i2c ) #tkhadmha
capteur = dht.DHT22(Pin(14))
light_capteur = ADC(12)
sys = Pin(17 , Pin.IN ,Pin.PULL_UP)
oled.invert(True)#t9leb el couleur t3 el ecrant
#oled.text('toutou', w , h) #bech nankteb al ecrant
while 1 :
reading = sys.value()
print("systhem off")
while reading == 1 :
reading = sys.value()
print("systhem on")
if reading== 0: break
t = capteur.temperature()
h = capteur.humidity()
l = light_capteur.read_u16()#unsining 2**16=65535()el capteur hatha ma3moul bch y9iis el dhleem ken nheb n9iss el dhaw nwaliw namlou 65535 - el valeur t3na
l = int(l*(100/65535))
oled.text(f'temp :{t}c',10,10)
oled.text(f'hum :{h}%',10,30)
oled.text(f'light :{l}%',10,50)
oled.show()
time.sleep_ms(10)
oled.fill(0)
if (l < 30) :
oled.invert(True)
else :
oled.invert(False)
#/ tatiik bel fassel // tatik entie
#ay heja tet3ewed fiil sec 9adeh men marra andha fréquance
#protocole de communication de iot : I2C / SPI / UART
#mesure testamal AO / etat testamal DO