from machine import Timer, Pin, ADC, I2C
from sh1106 import SH1106_I2C
import climaA, climaC, climaB
import time
import DisplayPrueba
import Menua_aldatu_edo_Ez
hor = ADC(Pin(34))
ver = ADC(Pin(35))
push = Pin(27,Pin.IN,Pin.PULL_UP)
hor.atten(ADC.ATTN_11DB)
ver.atten(ADC.ATTN_11DB)
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100_000)
asec=csec=0
temp=hum=moist=light=0
#variables de prueba de casa, reemplazo valores iniciales
t2 = 30
h2= 25
l2=12
m2= 7
#hemen sartu DisplayInitialValues()
oled = SH1106_I2C(i2c)
def menuClima():
global asec, csec, bsec
oled.text('Choose climate',0, 0)
oled.text('A climate:',0, 10)
oled.text('B climate: PUSH ',0, 23)
oled.text('C climate:',0, 36)
icon = [
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]]
pos_x, pos_y = 100, 10
for j, row in enumerate(icon):
for i, val in enumerate(row):
oled.pixel(i+pos_x, j+pos_y, val)
icon = [
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]]
pos_x, pos_y = 100, 36
for j, row in enumerate(icon):
for i, val in enumerate(row):
oled.pixel(i+pos_x, j+pos_y, val)
oled.show()
while asec<10 and csec<10 and push.value()==1:
hor_value = hor.read()
ver_value = ver.read()
print(f"asec: {asec}\t push: {push.value()}\t csec: {csec}\t hor:{hor_value}")
if hor_value<1000:
asec+=1
oled.text('Choosing A',0,50)
oled.show()
elif hor_value>3000:
csec+=1
oled.text('Choosing C',0,50)
oled.show()
else:
asec=0
csec=0
oled.fill_rect(0, 50, 128, 64,0)
if asec>=10 and csec<10:
temp,hum, moist, light = climaA.climaA()
elif csec>=10 and asec<10:
temp,hum, moist, light = climaC.climaC()
else:
temp,hum, moist, light =climaB.climaB()
menuClima()
oled.fill_rect(0, 0, 128, 64,0)
time.sleep(3)
DisplayPrueba.comparison(temp,hum,moist,light,t2,h2,l2,m2)
time.sleep(2)
Menua_aldatu_edo_Ez.change_parameters()
tim = Timer(0)
tim.init(period=1,
mode=Timer.PERIODIC,
callback=menuClima)
tim.deinit()