mmhome — ESP32-S3 simulation

An interactive ESP32-S3 circuit simulation you can run free in your browser on Velxio, by iliamaxsemov1712208.

Components

Sketch code

# MicroPython Blink for ESP32
from machine import Pin
import time
import networking
import neopixel


class STATUS:
    OK=0
    ERR=1
    CRIT=2
    NO_WIFI=3

class LedStyle():
    def __init__(self,color:tuple,pattern:list):
        self.color = color
        self.pattern = pattern # list led animation loop(ms) ON/OFF/ON...

LED_STYLES ={
    STATUS.OK: LedStyle((0, 255, 165), [10]),
    STATUS.ERR: LedStyle((255,0,0), [200,200,200,200,200,1000]),
    STATUS.CRIT: LedStyle((255,0,0), [10]),
    STATUS.NO_WIFI: LedStyle((255,255,0),[250,250])
}



SYS_STATUS = STATUS.ERR
SYS_LED = neopixel.NeoPixel(Pin(48), 1)
SYS_BUZZER_PIN = Pin(1, Pin.OUT)

_state_anim = 0
_state_lasttime = time.ticks_ms()
_last_status = None
    
def SHOW_STATE():
    global _state_anim, _state_lasttime, _last_status

    style = LED_STYLES[SYS_STATUS]
    color, pattern = style.color, style.pattern

    # смена статуса -> сброс анимации
    if _last_status != SYS_STATUS:
        _last_status = SYS_STATUS
        _state_anim = 0
        _state_lasttime = time.ticks_ms()
        SYS_LED[0] = color
        SYS_LED.write()
        return

    if len(pattern) == 1:
        return  # уже горит постоянно

    now = time.ticks_ms()
    if time.ticks_diff(now, _state_lasttime) >= pattern[_state_anim]:
        _state_lasttime = now
        _state_anim = (_state_anim + 1) % len(pattern)
        SYS_LED[0] = color if _state_anim % 2 == 0 else (0, 0, 0)
        SYS_LED.write()
        if SYS_STATUS in (STATUS.ERR, STATUS.CRIT):
            SYS_BUZZER_PIN.value(1 if _state_anim%2==0 else 0)
    


if __name__ == "__main__":
    while True:
        SHOW_STATE()