#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 16 // Jumlah LED pada strip
#define DATA_PIN 14 // Pin data yang terhubung ke LED strip
#define BRIGHTNESS 255 // Kecerahan maksimal (0-255)
#define FULL_BRIGHTNESS 255 // Kecerahan 100% untuk LED tengah
#define MID_BRIGHTNESS 153 // Kecerahan 60% untuk LED pertama dan ketiga (60% dari 255)
#define DIM_BRIGHTNESS 76 // Kecerahan 30% untuk LED yang belum menyala
#define Sign 4
int buttonState = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(Sign, INPUT);
// digitalWrite(Sign, LOW);
Serial.begin(115200);
strip.begin();
strip.setBrightness(BRIGHTNESS); // Set kecerahan awal
strip.show(); // Inisialisasi semua LED sebagai OFF
welcome();
}
void loop(){
buttonState = digitalRead(Sign);
Serial.println(buttonState);
if(buttonState == HIGH){
sign();
strip.clear(); // Matikan semua LED sebelum menyalakan yang baru
delay(20);
} else{
for(int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0)); // Warna merah
}
strip.show(); // Tampilkan perubahan pada LED strip
}
}
void welcome() {
int numActiveLeds = 3; // Jumlah LED yang menyala sekaligus
// Gerakan dari awal ke ujung strip
for (int i = 0; i < NUM_LEDS - numActiveLeds + 1; i++) {
strip.clear(); // Matikan semua LED sebelum menyalakan yang baru
for (int j = 0; j < numActiveLeds; j++) {
strip.setPixelColor(i + j, strip.Color(255, 0, 0)); // Warna merah, ganti dengan warna lain jika diperlukan
}
strip.show(); // Tampilkan perubahan pada LED strip
delay(50); // Sesuaikan kecepatan gerakan
}
// Gerakan kembali dari ujung ke awal strip
for (int i = NUM_LEDS - numActiveLeds; i >= 0; i--) {
strip.clear();
for (int j = 0; j < numActiveLeds; j++) {
strip.setPixelColor(i + j, strip.Color(255, 0, 0)); // Warna merah, ganti dengan warna lain jika diperlukan
}
strip.show();
delay(50);
}
for(int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0)); // Warna merah, bisa diganti
strip.show();
delay(20); // Sesuaikan kecepatan penyalakan bertahap
}
for(int brightness = BRIGHTNESS; brightness > BRIGHTNESS * 0.75; brightness--) {
strip.setBrightness(brightness);
strip.show();
delay(5); // Sesuaikan kecepatan peredupan
}
// Mengembalikan kecerahan ke normal secara bertahap
for(int brightness = BRIGHTNESS * 0.75; brightness <= BRIGHTNESS; brightness++) {
strip.setBrightness(brightness);
strip.show();
delay(5); // Sesuaikan kecepatan pengembalian kecerahan
}
}
void sign(){
// Mundur dari akhir ke awal
for (int offset = NUM_LEDS - 1; offset >= 0; offset--) {
for (int i = 0; i < NUM_LEDS; i++) {
int pos = (i + offset) % 6; // Menentukan posisi dalam kelompok 6 LED
if (pos == 0 || pos == 2) {
strip.setPixelColor(NUM_LEDS - 1 - i, strip.Color(MID_BRIGHTNESS, MID_BRIGHTNESS, 0)); // Kecerahan 60%
} else if (pos == 1) {
strip.setPixelColor(NUM_LEDS - 1 - i, strip.Color(FULL_BRIGHTNESS, FULL_BRIGHTNESS, 0)); // Kecerahan 100%
} else {
strip.setPixelColor(NUM_LEDS - 1 - i, strip.Color(DIM_BRIGHTNESS, DIM_BRIGHTNESS, 0)); // Kecerahan 30%
}
}
strip.show();
delay(70);
}
}