# #############################################################################
# ** Proyecto : pilas (stack)
# ** Plataforma : ESP32 / WROOM
# ** Herramienta : https://www.wokwi.com
# ** : Thonny aplicacion de escritorio descargar en www.thonny.org
# ** Compilador : wokwi Simulador online
# ** Version : 1.0
# ** Fecha/Hora : 28/02/2025, 1:35 am,
# **
# ** Simulación de una pila utlizadno Leds y botones para
# ** insertar y extraer objetos (leds) de la pila
# ** Versión : 1
# ** Revisión : A
# ** Release : 0
# ** Bugs & Fixes :
# ** Date : 27/02/2025,
# **
# ** By : Jorge Anzaldo
# ** contact : [email protected]
# ** twitter x : @janzaldob
# #############################################################################
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# : Librerias / Bibliotecas / Modulos | :
# ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
from machine import Pin
import time
# +-------------------------------------------------------------------------------
# | V A R I A B L E S / O B J E T O S - G L O B A L E S |
# +-------------------------------------------------------------------------------
# Definir pines de los LEDs
ledPins = [32, 33, 25, 26, 27, 14, 12, 13]
leds = [Pin(pin, Pin.OUT) for pin in ledPins]
# Definir pines de los botones
botonInsertar= Pin(16, Pin.IN, Pin.PULL_UP) # Botón para agregar a la pila
botonExtraer = Pin(17, Pin.IN, Pin.PULL_UP) # Botón para quitar de la pila
# Pila para almacenar LEDs
pila = []
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# | Definición y Desarrollo de Funciones |
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def insertaLed():
# Encender el siguiente LED y lo agrega a la pila
if len(pila) < len(leds):
led = leds[len(pila)]
led.value(1) # Encender LED
pila.append(led)
def extraerLed():
# Apaga el último LED encendido y lo quita de la pila
if pila:
led = pila.pop()
led.value(0) # Apagar LED
# ===============================================================================
# || ||
# || P R O G R A M A / F U N C I O N P R I N C I P A L ||
# || ||
# ===============================================================================
if __name__ == '__main__':
while True:
if not botonInsertar.value(): # Si se presiona el botón insertar
insertaLed()
time.sleep(0.3)
if not botonExtraer.value(): # Si se presiona el botón extraer
extraerLed()
time.sleep(0.3)
# ********************************************************************************
#
#
#
# R E F E R E N C I A S / C O M E N T A R I O S
#
# *********************************************************************************
Insertar
Extraer