2 — ESP32-S3 simulation

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

Components

Sketch code

// ESP32-S3 — Breathing LEDs (стабільна версія)
#include <math.h>

const int brightnessPot = 1;   // GPIO1
const int speedPot      = 2;   // GPIO2
const int ledPins[]     = {4, 5, 6};  // GPIO4,5,6 → бази транзисторів

const int PWM_FREQ = 5000;
const int PWM_RES  = 12;       // 0...4095

void setup() {
  Serial.begin(115200);
  
  for (int i = 0; i < 3; i++) {
    ledcAttach(ledPins[i], PWM_FREQ, PWM_RES);
  }
  
  analogReadResolution(12);
  analogSetAttenuation(ADC_11db);   // повний діапазон 0–3.3В
}

void loop() {
  int brightness = constrain(analogRead(brightnessPot), 0, 4095);
  int speedValue = constrain(analogRead(speedPot), 0, 4095);

  // Швидкість дихання: від 3 сек (повільно) до 0.25 сек (швидко)
  int period = map(speedValue, 0, 4095, 3000, 250);
  period = constrain(period, 250, 3000);

  unsigned long t = millis() % period;
  float phase = (float)t / period * 2.0f * PI;
  float breath = (sinf(phase - PI/2.0f) + 1.0f) / 2.0f;  // 0 → 1 → 0

  int pwm = constrain((int)(breath * brightness), 0, 4095);

  for (int i = 0; i < 3; i++) {
    ledcWrite(ledPins[i], pwm);
  }

  delay(5);
}

More projects by svitlana1981kusnirik