Membuat strobo dan whal waser dari led ws
Bagi sahabat miniatur yang hobi merakit sound system miniatur atau dekorasi dengan lampu LED, kode ini bisa menjadi panduan praktis untuk membuat efek cahaya yang keren. Kode ini menggunakan FastLED, sebuah library populer untuk mengendalikan lampu LED addressable seperti WS2812B/ sejenis nya,
![]() |
| Jpg |
Sebelum memulai, pastikan Anda memiliki perangkat berikut:
Mikrokontroler: Arduino, NodeMCU ESP8266, atau ESP32.
LED Strip: LED addressable (misalnya WS2812B atau WS2812 dan sejenisnya).
Kabel & Power Supply: Kabel jumper dan catu daya yang sesuai untuk LED.
Pastikan juga Anda sudah menginstal library FastLED di Arduino IDE Anda.
Pastikan library sesuai yang di rekomendasi kan pada video
https://youtu.be/7ACqr2CA9iE
==Struktur Dasar Kode
Kode ini dibagi menjad dua bagian utama yang mengendalikan dua grup LED yang berbeda:
Grup Utama (D2): Mengontrol lampu utama (strobo).
Grup K (D3): Mengontrol lampu kipas.
********
Skema Rangkaian (Wiring Diagram)
Pemasangan untuk pola searah sangat gampang. Ikuti langkah-langkah berikut:
Sambungkan pin Data (D-in) pada LED Kipas ke pin D1 pada mikrokontroler.
Sambungkan pin Data (D-in) pada LED Strip Utama ke pin D2 pada mikrokontroler.
Sambungkan pin 5V LED ke power supply 5V.
Sambungkan pin GND LED ke pin GND pada mikrokontroler dan ke GND power supply.
Perhitungan susunan led
Baris 1 = led 1-8
Baris 2 = led 9-16
Baris 3 = led 17-24
Baris 4 = led 25-32
Pada contoh tersebut pemasangan searah dan pin in harus di ambilkan dari out terakhir sehingga menjadi susunan berantai.
Begitupun untuk led blok selanjutnya juga sama susunan nya seperti di atas.
Kode Program (Copy-Paste)
Berikut adalah kode program lengkap yang sudah dibuat khusus untuk Anda. Cukup salin dan tempel ke Arduino IDE Anda.
==================================
/*code untuk strobo 8x4x4
Led ws di susun sebanyak 4blok,
Dari Susunan 4 baris Setiap baris berisi 8 led
Dan bisa untuk 4 blok
Dan juga terdiri 3 led untuk kipas */
#include <FastLED.h>
// Definisikan pin dan jumlah LED untuk setiap grup
#define LED_PIN_S D2 //strobo
#define LED_PIN_K D3 // kipas
#define NUM_LEDS_STRIP 128 //strobo 8x4x4
#define NUM_LEDS_K 3
CRGB leds1[NUM_LEDS_STRIP];
CRGB ledsK[NUM_LEDS_K];
// Atur nilai kecerahan untuk setiap grup
uint8_t brightness_leds1 = 10;
uint8_t brightness_ledsK = 250;
unsigned long modeStartTime = 0;
const long MODE_DURATION = 15000; // Durasi variasi utama (15 detik)
uint8_t currentMode = 0;
uint8_t colorIndex = 0;
CRGB colors[] = {
CRGB::Red, CRGB::Blue, CRGB::Green, CRGB::Purple, CRGB::Yellow, CRGB::White, CRGB::Orange};
const int NUM_COLORS = 7;
// Deklarasi fungsi-fungsi variasi efek
void twoWayMotion_V1();
void zigzag_V2();
void disappearing_V3();
void crissCross_V4();
void strobeRunOn_V5();
void strobeRunOff_V6();
void slowStrobe_V7();
void setup() {
// Inisialisasi LED strip utama pada pin D5
FastLED.addLeds<WS2812B, LED_PIN_S, GRB>(leds1, NUM_LEDS_STRIP);
// Inisialisasi LED kipas pada pin D3
FastLED.addLeds<WS2812, LED_PIN_K, GRB>(ledsK, NUM_LEDS_K);
modeStartTime = millis();
}
void loop() {
unsigned long now = millis();
// === Kontrol LED Kipas (Pin D3) ===
static unsigned long lastChangeK = 0;
static bool isFirstPattern = true;
if (now - lastChangeK >= 10000) { // Ganti pola setiap 10 detik dan sahabat miniatur juga bisa merubah berapa detik sesuai kebutuhan
lastChangeK = now;
isFirstPattern = !isFirstPattern;
}
if (isFirstPattern) {
ledsK[0] = CRGB::Red; //merah bisa anda ubah warna dengan yang lain
ledsK[1] = CRGB::Purple;
ledsK[2] = CRGB::Green;
} else {
ledsK[0] = CRGB::White;
ledsK[1] = CRGB::Blue;
ledsK[2] = CRGB::Yellow;
}
// === Kontrol LED Strip Utama (Pin D5) ===
if (millis() - modeStartTime >= MODE_DURATION) {
currentMode = (currentMode + 1) % 7;
modeStartTime = millis();
colorIndex = 0;
}
switch (currentMode) {
case 0: twoWayMotion_V1(); break;
case 1: zigzag_V2(); break;
case 2: disappearing_V3(); break;
case 3: crissCross_V4(); break;
case 4: strobeRunOn_V5(); break;
case 5: strobeRunOff_V6(); break;
case 6: slowStrobe_V7(); break;
}
// Atur kecerahan dan tampilkan
nscale8(ledsK,
NUM_LEDS_K, brightness_ledsK);
nscale8(leds1,
NUM_LEDS_STRIP, brightness_leds1);
FastLED.show();
}
// --- FUNGSI VARIASI EFEK ---
void twoWayMotion_V1() {
fill_solid(leds1, NUM_LEDS_STRIP, CRGB::Black);
long currentMillis = millis();
int speed = 300; // ubah kecepatan sesuai keinginan
int pos = (currentMillis / speed) % 8;
static int lastPos = 0;
if (pos < lastPos) { colorIndex = (colorIndex + 1) % NUM_COLORS;
} lastPos = pos;
CRGB currentColor = colors[colorIndex];
for (int set = 0; set < 4; set++) { int offset = set * 32;
leds1[offset + 0 * 8 + pos] = currentColor;
leds1[offset + 0 * 8 + (pos + 1) % 8] = currentColor; leds1[offset + 1 * 8 + pos] = currentColor;
leds1[offset + 1 * 8 + (pos + 1) % 8] = currentColor;
leds1[offset + 2 * 8 + (7 - pos)] = currentColor;
leds1[offset + 2 * 8 + (7 - pos + 8 - 1) % 8] = currentColor;
leds1[offset + 3 * 8 + (7 - pos)] = currentColor;
leds1[offset + 3 * 8 + (7 - pos + 8 - 1) % 8] = currentColor;
}
}
void zigzag_V2() {
fill_solid(leds1, NUM_LEDS_STRIP, CRGB::Black);
long currentMillis = millis();
int speed = 300;
int pos = (currentMillis / speed) % 8;
static int lastPos = 0;
if (pos < lastPos) { colorIndex = (colorIndex + 1) % NUM_COLORS;
} lastPos = pos;
CRGB currentColor = colors[colorIndex];
for (int set = 0; set < 4; set++) { int offset = set * 32;
leds1[offset + 0 * 8 + (pos + 1) % 8] = currentColor;
leds1[offset + 0 * 8 + (pos + 2) % 8] = currentColor;
leds1[offset + 0 * 8 + (pos + 5) % 8] = currentColor;
leds1[offset + 0 * 8 + (pos + 6) % 8] = currentColor;
leds1[offset + 1 * 8 + (pos + 1) % 8] = currentColor;
leds1[offset + 1 * 8 + (pos + 2) % 8] = currentColor;
leds1[offset + 1 * 8 + (pos + 5) % 8] = currentColor;
leds1[offset + 1 * 8 + (pos + 6) % 8] = currentColor;
leds1[offset + 2 * 8 + (pos + 3) % 8] = currentColor;
leds1[offset + 2 * 8 + (pos + 4) % 8] = currentColor;
leds1[offset + 2 * 8 + (pos + 7) % 8] = currentColor;
leds1[offset + 2 * 8 + (pos + 0) % 8] = currentColor;
leds1[offset + 3 * 8 + (pos + 3) % 8] = currentColor;
leds1[offset + 3 * 8 + (pos + 4) % 8] = currentColor;
leds1[offset + 3 * 8 + (pos + 7) % 8] = currentColor;
leds1[offset + 3 * 8 + (pos + 0) % 8] = currentColor;
}
}
void disappearing_V3() {
fill_solid(leds1,
NUM_LEDS_STRIP,
CRGB::Black);
long currentMillis = millis();
int speed = 350;
int pos = (currentMillis / speed) % 4;
static int lastPos = 0;
static bool isRed = true;
if (pos < lastPos) { isRed = !isRed; } lastPos = pos;
CRGB currentColor = isRed ?
CRGB::Red :
CRGB::Blue;
for (int set = 0; set < 4; set++) { int offset = set * 32;
for (int i = 0; i < 4; i++) { leds1[offset + i * 8 + pos] = currentColor; leds1[offset + i * 8 + (7 - pos)] = currentColor;
}
}
}
void crissCross_V4() {
fill_solid(leds1, NUM_LEDS_STRIP, CRGB::Black);
static long lastSwitchTime = 0;
const long SWITCH_INTERVAL = 1000;
static bool isState1 = true;
static bool isRedTopLeft = true; if (millis() - lastSwitchTime >= SWITCH_INTERVAL) { isState1 = !isState1;
lastSwitchTime = millis();
if (isState1) { isRedTopLeft = !isRedTopLeft;
}
}
CRGB colorA, colorB;
if (isRedTopLeft) {
colorA = CRGB::Red;
colorB = CRGB::Blue;
}
else { colorA = CRGB::Blue;
colorB = CRGB::Red;
}
for (int set = 0; set < 4; set++)
{ int offset = set * 32; if (isState1) {
for (int i = 0; i < 4; i++) {
leds1[offset + 0 * 8 + i] = colorA; leds1[offset + 1 * 8 + i] = colorA;
}
for (int i = 0; i < 4; i++) {
leds1[offset + 2 * 8 + (i + 4)] = colorB; leds1[offset + 3 * 8 + (i + 4)] = colorB; }
}
else {
for (int i = 0; i < 4; i++) {
leds1[offset + 0 * 8 + (i + 4)] = colorB; leds1[offset + 1 * 8 + (i + 4)] = colorB;
}
for (int i = 0; i < 4; i++) {
leds1[offset + 2 * 8 + i] = colorA;
leds1[offset + 3 * 8 + i] = colorA;
}
}
}
}
void strobeRunOn_V5() {
fill_solid(leds1,
NUM_LEDS_STRIP,
CRGB::Black);
static long lastChangeTime = 0;
const long CHANGE_INTERVAL = 500;
static int currentSet = 0; if (millis() - lastChangeTime >= CHANGE_INTERVAL) {
currentSet = (currentSet + 1);
if (currentSet > 4) { currentSet = 0; }
lastChangeTime = millis(); }
for (int i = 0; i < currentSet; i++) {
for (int j = 0; j < 32; j++)
{ leds1[i * 32 + j] =
CRGB::White;
}
}
}
void strobeRunOff_V6() {
fill_solid(leds1,
NUM_LEDS_STRIP,
CRGB::Black);
static long lastChangeTime = 0;
const long CHANGE_INTERVAL = 500;
static int currentSet = 0;
if (millis() - lastChangeTime >= CHANGE_INTERVAL) {
currentSet = (currentSet + 1) % 4;
lastChangeTime = millis(); }
for (int i = 0; i < 32; i++) { leds1[currentSet * 32 + i] = CRGB::White; }
}
void slowStrobe_V7() {
fill_solid(leds1,
NUM_LEDS_STRIP,
CRGB::Black);
static long lastFlashTime = 0;
const long FLASH_INTERVAL = 1000;
static bool isOn = true;
static int currentColorIndex = 0;
if (millis() - lastFlashTime >= FLASH_INTERVAL) { isOn = !isOn; lastFlashTime = millis();
if (isOn) { currentColorIndex = (currentColorIndex + 1) % NUM_COLORS;
}
}
if (isOn) { fill_solid(leds1, NUM_LEDS_STRIP, colors[currentColorIndex]); }
else { fill_solid(leds1, NUM_LEDS_STRIP,
CRGB::Black);
}
}
=================
Dengan code tersebut sahabat sudah mendapatkan 7 variasi led strobo dan 2 variasi led kipas
Sahabat juga ber experimen dengan variasi " Lain
Like share dan comen sahabat sangat kami nantikan
Semoga berhasil


Komentar
Posting Komentar