You are on page 1of 3

LEDS

from machine import Pin


import time
boton = Pin(14,Pin.IN)
boton2 = Pin(15,Pin.IN)
Led = Pin(18,Pin.OUT)
while True:
boton_value = boton.value()
boton2_value = boton2.value()
if boton_value == 1:
Led.value(1)
if boton2_value == 1:
Led.value(0)

POTENCIOMETRO + RGB
from machine import Pin
import machine
import neopixel
import time
from machine import ADC
potenciometro = ADC(Pin(32))
potenciometro.atten(ADC.ATTN_11DB)
led=neopixel.NeoPixel(machine.Pin(4),3)
while True:
potenciometro_value= potenciometro.read()
print(potenciometro_value)
if potenciometro_value > 1250:
led[0]=(255,0,0)
led[1]=(0,0,0)
led[2]=(0,0,0)
led.write()
if potenciometro_value > 2500:
led[0]=(0,0,0)
led[1]=(0,255,0)
led[2]=(0,0,0)
led.write()
if potenciometro_value > 3750:
led[0]=(0,0,0)
led[1]=(0,0,0)
led[2]=(0,0,255)
led.write()

SENSOR ANALOGO
from machine import Pin
import time
from machine import ADC
potenciometro = ADC(Pin(32))
potenciometro.atten(ADC.ATTN_11DB)
Led= Pin(18,Pin.OUT)
while True:
potenciometro_value= potenciometro.read()
print(potenciometro_value)
if potenciometro_value > 2000:
Led.value(1)
else:
Led.value(0)

Sensor PIR + Servomotor


from machine import Pin, PWM #libreria de servomotores
from time import sleep #libreria delay
import machine
sensor = Pin(23 ,Pin.IN)
mosquita = PWM(Pin(26)) #puerto de servomotor
mosquita.freq(60) #frecuencia de servo
step = 4 #rango de desfase de servo
duty = 60 #grados de inicio
while True:
sensor_value = sensor.value()
if sensor_value == 1:
mosquita.duty(duty+30)
else:
mosquita.duty(duty+120)

PANTALLA LED I2C ssd1306


from machine import Pin, I2C, ADC
import ssd1306 #nombre de pantalla
from time import sleep

i2c= I2C(-1, sda=Pin(21),scl=Pin(22))


display = ssd1306.DISPLAY= SSD1306_I2C(128, 64, i2c)
while True:
display.fill(0)
display.text('hola MVS',12,0,20)
display.show()
sleep(1)

POEMA EN PANTALLA 12C


from machine import Pin, I2C, ADC
import ssd1306
from time import sleep
i2c= I2C (-1, sda= Pin(21),scl= Pin(22))
display=ssd1306.SSD1306_I2C(128,64,i2c)
while True:
display.fill(0)
#escribir
display.text("Little Jane",12,10,20) #posicion X,Y y tamaño de
texto
display.text("who'd read all",12,20,20) #posicion X,Y y tamaño
de texto
display.text("about bears,",12,30,20) #posicion X,Y y tamaño de
texto
display.text("went to see",12,40,20) #posicion X,Y y tamaño de
texto
display.text("them asleep in",12,50,20) #posicion X,Y y tamaño
de texto
display.show()
sleep(5)
display.fill(0)
display.text("their lairs;",12,10,20) #posicion X,Y y tamaño de
texto
display.text("this was a",12,20,20) #posicion X,Y y tamaño de
texto
display.text("mistake:",12,30,20) #posicion X,Y y tamaño de
texto
display.text("they were all",12,40,20) #posicion X,Y y tamaño de
texto
display.text("wide awake.",12,50,20) #posicion X,Y y tamaño de
texto
display.show()
sleep(5)

Sensor de fuego (digital) + Pantalla lcd


from machine import Pin, I2C, ADC
import ssd1306
from time import sleep
sensorfuego= Pin(23,Pin.IN)
i2c= I2C (-1, sda= Pin(21),scl= Pin(22))
display=ssd1306.SSD1306_I2C(128,64,i2c)
while True:
display.fill(0)
display.text("Fecha: 26/05/23",8,10,20) #posicion X,Y y tamaño
de texto
display.text("Dia: Viernes",8,20,20) #posicion X,Y y tamaño de
texto
display.text("Hora: 10:10a.m.",8,30,20) #posicion X,Y y tamaño
de texto
display.text("ESTADO:",8,50,20) #posicion X,Y y tamaño de texto
display.show()
sleep(1)
sensorfuego_value=sensorfuego.value()
if sensorfuego_value==1:
display.text("ALERTA",80,50,20) #posicion X,Y y tamaño de
texto
display.show()
sleep(3)
else:
display.text("-----",80,50,20) #posicion X,Y y tamaño de
texto
display.show()
sleep(1)

You might also like