#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define LED_PIN 3
#define WIDTH 20
#define HEIGHT 5
#define POT_PIN 0
#define LED_COUNT (WIDTH * HEIGHT)
// Pin switch dan tombol
#define SW1 4
#define SW2 5
#define SW3 6
#define BTN4 7
#define BTN5 1 // Pin untuk tombol on/off
int strobo_1 = 30;
int strobo_2 = 80;
int strobo_3 = 50;
int strobo_4 = 100;
int freq_1 = 10;
int freq_2 = 30;
int freq_3 = 100;
int freq_pattern_1 = 40;
float speedMultiplier = 1;
// Konfigurasi OLED
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin (gunakan -1 jika tidak ada pin reset terpisah)
#define SCREEN_ADDRESS 0x3C // Alamat I2C untuk OLED (biasanya 0x3C atau 0x3D)
// Pin I2C untuk ESP32 C3 Super Mini
#define SDA_PIN 8
#define SCL_PIN 9
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Variabel global untuk status
int brightness = 0;
String currentMode = "Rainbow";
int potValue = 0;
// Fungsi konversi koordinat matriks zig-zag ke index strip
int xyToIndex(int x, int y) {
if (y % 2 == 0) {
return y * WIDTH + x; // baris genap → kiri ke kanan
} else {
return y * WIDTH + (WIDTH - 1 - x); // baris ganjil → kanan ke kiri
}
}
void setup() {
Serial.begin(115200);
// Inisialisasi I2C dengan pin kustom
Wire.begin(SDA_PIN, SCL_PIN);
// Inisialisasi OLED
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("ESP32 C3");
display.println("Initializing...");
display.display();
delay(1000);
strip.begin();
strip.show();
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
pinMode(SW3, INPUT_PULLUP);
pinMode(BTN4, INPUT_PULLUP);
pinMode(BTN5, INPUT_PULLUP);
// Set ADC resolution untuk ESP32
analogReadResolution(12); // ESP32 menggunakan 12-bit ADC (0-4095)
Serial.println("Setup complete!");
}
void loop() {
// Baca nilai potensiometer (0-4095 untuk 12-bit ADC)
int potValue = analogRead(POT_PIN);
// Map nilai potensiometer ke brightness (0-255)
brightness = map(potValue, 0, 4095, 0, 200);
// Set brightness
strip.setBrightness(brightness);
bool s1 = !digitalRead(SW1);
bool s2 = !digitalRead(SW2);
bool s3 = !digitalRead(SW3);
bool b4 = !digitalRead(BTN4);
bool b5 = !digitalRead(BTN5);
// Tentukan mode berdasarkan input
if (!s1 && !s2 && !s3 && !b4 && !b5) {
currentMode = "Rainbow";
baseRainbowTwinkle();
} else if (s1) {
currentMode = "<- L";
arrowRightToLeft();
} else if (s2) {
currentMode = "R ->";
arrowLeftToRight();
} else if (s3) {
currentMode = "<-L - R->";
arrowCenterOut();
} else if (b4) {
currentMode = "X- Brake -X";
crossCenter();
} else if (b5) {
currentMode = "Strobo";
runStroboSequence();
}
// Update display OLED
updateDisplay(s1, s2, s3, b4, b5);
}
bool checkButton() {
bool b5 = !digitalRead(BTN5);
return (b5);
}
void updateDisplay(bool s1, bool s2, bool s3, bool b4, bool b5) {
display.clearDisplay();
// Header
display.setTextSize(1);
display.setCursor(0, 0);
display.println("ESP LED Brake System");
display.drawLine(0, 10, SCREEN_WIDTH, 10, SSD1306_WHITE);
// Mode saat ini
display.setCursor(0, 15);
display.print("Mode: ");
display.println(currentMode);
// Brightness
display.setCursor(0, 25);
display.print("Bright: ");
display.print(brightness);
display.print("/200");
// Bar brightness
int barWidth = map(brightness, 0, 200, 0, SCREEN_WIDTH - 20);
display.drawRect(0, 35, SCREEN_WIDTH - 20, 8, SSD1306_WHITE);
display.fillRect(1, 36, barWidth - 2, 6, SSD1306_WHITE);
// Status switch
display.setCursor(0, 47);
display.print("SW:");
display.print(s1 ? "1" : "-");
display.print(s2 ? "2" : "-");
display.print(s3 ? "3" : "-");
display.print(b4 ? "B" : "-");
// Nilai ADC
display.setCursor(0, 56);
display.print("ADC: ");
display.print(potValue);
display.display();
}
/* === MODE 1: Animasi Dasar - Running Twinkle Rainbow === */
void baseRainbowTwinkle() {
static uint8_t offset = 0;
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
int i = xyToIndex(x, y);
uint8_t hue = (x * 10 + y * 20 + offset) & 255;
if (random(0, 100) > 90) {
strip.setPixelColor(i, Wheel(hue));
} else {
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
}
}
strip.show();
offset++;
delay(80);
}
/* === MODE 2: Arrow dari kanan ke kiri (continuous multiple arrows) === */
void arrowRightToLeft() {
static int offset = 0;
int centerY = HEIGHT / 2;
int arrowSpacing = 5; // Jarak antar arrow
strip.clear();
// Loop untuk menampilkan multiple arrows
for (int baseX = WIDTH - 1 + offset; baseX >= -5; baseX -= arrowSpacing) {
for (int i = -2; i <= 2; i++) {
int y = centerY + i;
if (y >= 0 && y < HEIGHT) {
// Gambar body arrow
int bodyX = baseX - abs(i);
if (bodyX >= 0 && bodyX < WIDTH) {
strip.setPixelColor(xyToIndex(bodyX, y), strip.Color(255, 255, 0));
}
// Gambar tip arrow (kepala panah)
if (i == 0 && baseX >= 0 && baseX < WIDTH) {
strip.setPixelColor(xyToIndex(baseX, y), strip.Color(255, 0, 0));
}
}
}
}
strip.show();
offset++;
// Reset offset ketika sudah melewati satu cycle
if (offset >= arrowSpacing) {
offset = 0;
}
delay(30);
}
/* === MODE 3: Arrow dari kiri ke kanan (continuous multiple arrows) === */
void arrowLeftToRight() {
static int offset = 0;
int centerY = HEIGHT / 2;
int arrowSpacing = 5; // Jarak antar arrow
strip.clear();
// Loop untuk menampilkan multiple arrows
for (int baseX = -offset; baseX <= WIDTH + 5; baseX += arrowSpacing) {
for (int i = -2; i <= 2; i++) {
int y = centerY + i;
if (y >= 0 && y < HEIGHT) {
// Gambar body arrow
int bodyX = baseX + abs(i);
if (bodyX >= 0 && bodyX < WIDTH) {
strip.setPixelColor(xyToIndex(bodyX, y), strip.Color(255, 255, 0));
}
// Gambar tip arrow (kepala panah)
if (i == 0 && baseX >= 0 && baseX < WIDTH) {
strip.setPixelColor(xyToIndex(baseX, y), strip.Color(255, 0, 0));
}
}
}
}
strip.show();
offset++;
// Reset offset ketika sudah melewati satu cycle
if (offset >= arrowSpacing) {
offset = 0;
}
delay(30);
}
/* === MODE 4: Arrow dari tengah ke luar (continuous multiple arrows) === */
void arrowCenterOut() {
static int offset = 0;
int mid = WIDTH / 2;
int centerY = HEIGHT / 2;
int arrowSpacing = 6; // Jarak antar arrow
strip.clear();
// Loop untuk menampilkan multiple arrows ke kiri dan kanan
for (int step = offset; step <= mid + 5; step += arrowSpacing) {
// --- Panah ke kiri ---
int tipLeft = mid - step;
for (int i = -2; i <= 2; i++) {
int y = centerY + i;
if (y >= 0 && y < HEIGHT) {
int baseX = tipLeft + abs(i);
if (baseX >= 0 && baseX < WIDTH)
strip.setPixelColor(xyToIndex(baseX, y), strip.Color(255, 100, 0));
if (i == 0 && tipLeft >= 0 && tipLeft < WIDTH)
strip.setPixelColor(xyToIndex(tipLeft, y), strip.Color(100, 255, 100));
}
}
// --- Panah ke kanan ---
int tipRight = mid + step - (WIDTH % 2 == 0 ? 1 : 0);
for (int i = -2; i <= 2; i++) {
int y = centerY + i;
if (y >= 0 && y < HEIGHT) {
int baseX = tipRight - abs(i);
if (baseX >= 0 && baseX < WIDTH)
strip.setPixelColor(xyToIndex(baseX, y), strip.Color(255, 100, 0));
if (i == 0 && tipRight >= 0 && tipRight < WIDTH)
strip.setPixelColor(xyToIndex(tipRight, y), strip.Color(100, 255, 100));
}
}
}
strip.show();
offset++;
// Reset offset ketika sudah melewati satu cycle
if (offset >= arrowSpacing) {
offset = 0;
}
delay(50);
}
/* === MODE 5: Cross Panah dari Luar ke Tengah (continuous multiple arrows) === */
void crossCenter() {
static int offset = 0;
int centerY = HEIGHT / 2;
int half = WIDTH / 2;
int arrowSpacing = 6; // Jarak antar arrow
strip.clear();
// Loop untuk menampilkan multiple arrows
for (int step = offset; step <= half + 5; step += arrowSpacing) {
// --- Panah dari kanan ke tengah (menghadap kiri) ---
int tipRight = WIDTH - 1 - step;
for (int i = -2; i <= 2; i++) {
int y = centerY + i;
if (y < 0 || y >= HEIGHT) continue;
int baseX = tipRight + abs(i);
if (baseX >= 0 && baseX < WIDTH)
strip.setPixelColor(xyToIndex(baseX, y), strip.Color(255, 0, 0));
if (i == 0 && tipRight >= 0 && tipRight < WIDTH)
strip.setPixelColor(xyToIndex(tipRight, y), strip.Color(100, 255, 100));
}
// --- Panah dari kiri ke tengah (menghadap kanan) ---
int tipLeft = step;
for (int i = -2; i <= 2; i++) {
int y = centerY + i;
if (y < 0 || y >= HEIGHT) continue;
int baseX = tipLeft - abs(i);
if (baseX >= 0 && baseX < WIDTH)
strip.setPixelColor(xyToIndex(baseX, y), strip.Color(255, 0, 0));
if (i == 0 && tipLeft >= 0 && tipLeft < WIDTH)
strip.setPixelColor(xyToIndex(tipLeft, y), strip.Color(100, 255, 100));
}
}
strip.show();
offset++;
// Reset offset ketika sudah melewati satu cycle
if (offset >= arrowSpacing) {
offset = 0;
}
delay(50);
}
/* === Fungsi Wheel === */
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
// ============================================================= //
// ====================STROBO=================================== //
// Fungsi helper untuk mengkonversi koordinat X,Y ke index LED
// Asumsi: LED matrix 20x5 dengan snake pattern (zigzag)
int getPixelIndex(int x, int y) {
if (x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT) return -1;
// Snake pattern: baris ganjil kiri-kanan, baris genap kanan-kiri
if (y % 2 == 0) {
return y * WIDTH + x;
} else {
return y * WIDTH + (WIDTH - 1 - x);
}
}
// Fungsi untuk set warna berdasarkan region kiri/kanan
void setRegionColor(int startCol, int endCol, uint32_t color) {
for (int y = 0; y < HEIGHT; y++) {
for (int x = startCol; x < endCol; x++) {
int idx = getPixelIndex(x, y);
if (idx >= 0) strip.setPixelColor(idx, color);
}
}
}
void runStroboSequence() {
// Strobo 5 - Kiri Merah, Kanan Biru bergantian
if (!checkButton()) { strip.clear(); strip.show(); return; }
kiri_merah();
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_2);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
kanan_biru();
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_2);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
// Strobo 6 - Kiri-Kanan bergantian cepat
for (int i = 0; i <= 3; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
campuran_kiri_kanan();
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
}
// Strobo 7 - Kiri Merah, Tengah Putih, Kanan Biru
if (!checkButton()) { strip.clear(); strip.show(); return; }
campuran_kiri_tengah_kanan();
customDelay(strobo_2);
// Strobo 9 - Alternating kiri-kanan-tengah
if (!checkButton()) { strip.clear(); strip.show(); return; }
kiri_merah_only();
customDelay(strobo_2);
if (!checkButton()) { strip.clear(); strip.show(); return; }
tengah_putih();
customDelay(strobo_2);
if (!checkButton()) { strip.clear(); strip.show(); return; }
kanan_biru_only();
customDelay(strobo_2);
// Strobo 11 - Pattern kiri-tengah-kanan dengan putih
for (int i = 0; i <= 6; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
pattern_kiri_tengah_kanan_putih();
customDelay(strobo_1);
}
// Strobo 12 - Repeat pattern
for (int i = 0; i <= 6; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
pattern_kiri_tengah_kanan_putih();
customDelay(strobo_1);
}
// Strobo 13 - Alternating kiri kanan cepat
for (int i = 0; i <= 6; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
kiri_merah_flash();
customDelay(strobo_2);
if (!checkButton()) { strip.clear(); strip.show(); return; }
kanan_biru_flash();
customDelay(strobo_2);
if (!checkButton()) { strip.clear(); strip.show(); return; }
kiri_merah_flash();
customDelay(strobo_2);
if (!checkButton()) { strip.clear(); strip.show(); return; }
kiri_merah_flash();
customDelay(strobo_2);
}
// Strobo 14 - Pattern diagonal
for (int i = 0; i <= 6; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
pattern_diagonal_1();
}
// Strobo 15 - Pattern diagonal repeat
for (int i = 0; i <= 6; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
pattern_diagonal_1();
}
// Strobo 18 - Putih tengah expand
if (!checkButton()) { strip.clear(); strip.show(); return; }
putih_expand();
// Strobo 19 - Rainbow kiri ke kanan
for (int i = 0; i < 3; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
rainbow_kiri_kanan();
}
}
void customDelay(int delayTime) {
unsigned long startTime = millis();
while (millis() - startTime < delayTime) {
if (!checkButton()) {
strip.clear();
strip.show();
return;
}
delay(1);
}
}
//***************************************************
// FUNGSI WARNA - MATRIX 20x5 (KIRI-KANAN)
//***************************************************
void kiri_merah() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 10, strip.Color(255, 0, 0)); // Kolom 0-9 (kiri)
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_1);
}
}
void kanan_biru() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(10, 20, strip.Color(0, 0, 255)); // Kolom 10-19 (kanan)
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_1);
}
}
void tengah_putih() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(7, 13, strip.Color(255, 255, 255)); // Kolom 7-12 (tengah)
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_1);
}
}
void campuran_kiri_tengah_kanan() {
for (int j = 0; j <= 6; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 7, strip.Color(255, 0, 0)); // Kiri merah
setRegionColor(7, 13, strip.Color(255, 255, 255)); // Tengah putih
setRegionColor(13, 20, strip.Color(0, 0, 255)); // Kanan biru
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_1);
}
}
void campuran_kiri_kanan() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 10, strip.Color(255, 0, 0)); // Kiri merah
setRegionColor(10, 20, strip.Color(0, 0, 255)); // Kanan biru
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
}
}
void kiri_merah_only() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 10, strip.Color(255, 0, 0));
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
}
}
void kanan_biru_only() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(10, 20, strip.Color(0, 0, 255));
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
}
}
void pattern_kiri_tengah_kanan_putih() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 5, strip.Color(255, 0, 0));
setRegionColor(7, 13, strip.Color(255, 255, 255));
setRegionColor(15, 20, strip.Color(0, 0, 255));
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
}
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 5, strip.Color(255, 0, 0));
setRegionColor(7, 13, strip.Color(0, 0, 0));
setRegionColor(15, 20, strip.Color(0, 0, 255));
strip.show();
customDelay(strobo_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_1);
}
}
void kiri_merah_flash() {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 10, strip.Color(255, 0, 0));
strip.show();
customDelay(strobo_3);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_3);
}
void kanan_biru_flash() {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(10, 20, strip.Color(0, 0, 255));
strip.show();
customDelay(strobo_3);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(strobo_3);
}
void pattern_diagonal_1() {
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(0, 5, strip.Color(255, 0, 0));
setRegionColor(15, 20, strip.Color(0, 0, 255));
strip.show();
customDelay(freq_pattern_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(freq_pattern_1);
}
for (int j = 0; j <= 3; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
setRegionColor(5, 10, strip.Color(255, 0, 0));
setRegionColor(10, 15, strip.Color(0, 0, 255));
strip.show();
customDelay(freq_pattern_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(freq_pattern_1);
}
}
void putih_expand() {
for (int i = 0; i <= 3; i++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
// Bagian tengah
setRegionColor(9, 11, strip.Color(255, 255, 255));
strip.show();
customDelay(freq_pattern_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(freq_pattern_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
// Expand ke samping
setRegionColor(7, 9, strip.Color(255, 255, 255));
setRegionColor(11, 13, strip.Color(255, 255, 255));
strip.show();
customDelay(freq_pattern_1);
if (!checkButton()) { strip.clear(); strip.show(); return; }
strip.clear();
customDelay(freq_pattern_1);
}
}
void rainbow_kiri_kanan() {
// Merah dari kiri
for (int j = 0; j < 1; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
int idx = getPixelIndex(x, y);
if (idx >= 0) strip.setPixelColor(idx, strip.Color(255, 0, 0));
}
strip.show();
}
delay(5);
strip.clear();
}
// Biru dari kanan
for (int j = 0; j < 1; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
for (int x = WIDTH - 1; x >= 0; x--) {
for (int y = 0; y < HEIGHT; y++) {
int idx = getPixelIndex(x, y);
if (idx >= 0) strip.setPixelColor(idx, strip.Color(0, 0, 255));
}
strip.show();
}
delay(5);
strip.clear();
}
// Putih dari kiri
for (int j = 0; j < 1; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
int idx = getPixelIndex(x, y);
if (idx >= 0) strip.setPixelColor(idx, strip.Color(255, 255, 255));
}
strip.show();
}
delay(5);
strip.clear();
}
// Putih dari kanan
for (int j = 0; j < 1; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
for (int x = WIDTH - 1; x >= 0; x--) {
for (int y = 0; y < HEIGHT; y++) {
int idx = getPixelIndex(x, y);
if (idx >= 0) strip.setPixelColor(idx, strip.Color(255, 255, 255));
}
strip.show();
}
delay(5);
strip.clear();
}
// Biru dari kiri
for (int j = 0; j < 1; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
int idx = getPixelIndex(x, y);
if (idx >= 0) strip.setPixelColor(idx, strip.Color(0, 0, 255));
}
strip.show();
}
delay(5);
strip.clear();
}
// Merah dari kanan
for (int j = 0; j < 1; j++) {
if (!checkButton()) { strip.clear(); strip.show(); return; }
for (int x = WIDTH - 1; x >= 0; x--) {
for (int y = 0; y < HEIGHT; y++) {
int idx = getPixelIndex(x, y);
if (idx >= 0) strip.setPixelColor(idx, strip.Color(255, 0, 0));
}
strip.show();
}
delay(5);
strip.clear();
}
}Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1