ESP32 3D sound wave with sound sensor display on an OLED
Автор: Electricum
Загружено: 2024-12-19
Просмотров: 294
Описание:
Reading Sound Data
The sound sensor measures sound intensity as analog values (0–4095 for ESP32 ADC).
These values are read using analogRead(SOUND_SENSOR_PIN).
Non-Linear Scaling for Softer Sounds
Since soft sounds produce small changes, they are amplified using a power law:
float normalized = pow((float)soundLevel / 4095, 1.5);
The pow function applies a non-linear curve, giving more weight to smaller values.
This ensures quiet sounds still produce visible waves while keeping loud sounds proportional.
Amplitude Adjustment
The calculated sound level (normalized) is combined with:
baseAmplitude: Ensures a baseline movement, even in silence.
sensitivity: Magnifies the effect of changes in sound level.
A smoothing formula:
amplitude = baseAmplitude + (amplitude * 0.7 + (normalized * sensitivity) * 0.3);
ensures:
Smooth transitions between frames (dampens abrupt changes).
Responsiveness to new sound inputs.
Waveform Creation:
A sine wave pattern is generated:
waveData[0][x] = SCREEN_HEIGHT / 2 + amplitude * sin((x * 0.2) + millis() / 100.0);
SCREEN_HEIGHT / 2: Centers the wave vertically.
amplitude: Determines the wave height based on sound intensity.
sin function: Creates an oscillating wave along the x-axis.
millis(): Adds time-dependent motion for dynamic undulations.
Depth Layers (3D Effect)
Multiple layers of waveforms are stored in waveData, creating a sense of depth:
The oldest wave is pushed further back (shifted down layers).
The newest wave is drawn at the front.
OLED Display
The waves are drawn pixel by pixel for each depth layer:
display.drawPixel(x, y, SSD1306_WHITE);
Layers are drawn from back to front, so the front wave is always most visible.
Real-Time Animation
Each loop cycle:
Reads the sound sensor.
Updates wave data.
Clears the screen and redraws the new frame.
Code:
https://github.com/ukkokalevala/3Dwav...
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: