This is not, a super complicated project and uses no libraries! I would recommend this to any beginner as it is very fun and quick. I recommend that when you do make this project you expand it to as many leds as you can!
🛠️ เจาะลึกเบื้องหลังการทำงาน (Deep Dive / Technical Analysis)
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.
The Math Behind the Flow
To achieve organic fading, you must use Pulse Width Modulation (PWM).
- The Array: You line up 6 LEDs exclusively on Arduino PWM pins (e.g.,
3, 5, 6, 9, 10, 11). - 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; - 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
0and255!
- 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!).