กลับไปหน้ารวมไฟล์
led-wave-27b109-en.md

Visual Math: The LED Sine Wave

Standard LED Chasers just bounce a light back and forth mechanically. The LED Wave project elevates this by using mathematical trigonometry to dictate brightness, creating incredibly smooth, organic fading animations that perfectly mimic a water wave.

button_led_basic_interaction_1772681969235.png

The Math Behind the Flow

To achieve organic fading, you must use Pulse Width Modulation (PWM).

  1. The Array: You line up 6 LEDs exclusively on Arduino PWM pins (e.g., 3, 5, 6, 9, 10, 11).
  2. The Equation: Instead of manually setting the brightness, the code calculates the sin() value of a continuously shifting variable (representing time or phase). float brightness = (sin(phase + LED_Position) + 1) * 127.5;
  3. The Break Down:
    • A standard sine wave swings between -1 and +1.
    • We add +1 so it swings between 0 and 2.
    • We multiply by 127.5 so the final output is a perfect PWM number between 0 and 255!
  4. Phase Shifting: By slightly offsetting the phase for each LED in the array, LED 1 might be at max brightness while LED 2 is at 80% and LED 3 is at 10%. As the phase number linearly increases over time, the "swell" of the wave naturally glides across the breadboard.

Setup Requirements

  • Arduino Uno/Nano: Need 6 actual hardware PWM pins.
  • 6x LEDs and 6x Resistors.
  • Breadboard.
  • (Advanced Upgrade: Use a WS2812B NeoPixel strip to execute this math on 100 LEDs simultaneously!).

ข้อมูล Frontmatter ดั้งเดิม

title: "Led Wave!"
description: "Riding the sine wave! Program a stunning, fluid wave animation across a massive array of LEDs by integrating advanced trigonometric math directly into your C++ code."
category: "Basic Electronics"
difficulty: "Intermediate"