import machine
import time
#from machine import Pin
#from time import sleep
from machine import Pin, I2C # importamos la funcion pin del modulo machine y la función I2C
from ssd1306 import SSD1306_I2C
import framebuf
WIDTH = 128 # declaramos el ancho de pantalla OLED
HEIGHT = 64 # declaramos la altura de la pantalla OLED
i2c = I2C(0) # Inicializa I2C usando los valores predeterminados de
# I2C0, SCL= Pin GP9, SDA= Pin GP8, freq = 400000
print("I2C Address : "+hex(i2c.scan()[0]).upper()) # Muestra la dirección del dispositivo en la shell o consola
print("I2C Configuration: "+str(i2c)) # Muestra la configuración I2C en la shell o consola
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)
red_led = machine.Pin(12, machine.Pin.OUT)
blue_led = machine.Pin(13, machine.Pin.OUT)
yellow_led = machine.Pin(14, machine.Pin.OUT)
#button = Pin(4, Pin.IN)
red_button = machine.Pin(6, machine.Pin.IN, machine.Pin.PULL_UP)
blue_button = machine.Pin(6, machine.Pin.IN, machine.Pin.PULL_UP)
yellow_button = machine.Pin(6, machine.Pin.IN, machine.Pin.PULL_UP)
light_sensor = machine.ADC(machine.Pin(28)) # create ADC object on ADC pin
# Agrega el texto
oled.text("Nairobi",5,5)
oled.text("Temp",5,15)
oled.text("Humidity",5,35)
oled.text("Light",5,45)
oled.show()
#connected button to 3.3v
while True:
light_value = light_sensor.read_u16()
print("Light Intensity :",light_value)
print("\n\n")
red_button_state = red_button.value()
print("Button state", red_button_state) #high / low
red_led.value(red_button_state)
blue_button_state = blue_button.value()
print("Button state", blue_button_state) #high / low
blue_led.value(blue_button_state)
yellow_button_state = yellow_button.value()
print("Button state", yellow_button_state) #high / low
yellow_led.value(yellow_button_state)