#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 16
#define BUTTON_PIN 2
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// צבעים: כתום, צהוב, לבן, כחול
uint8_t colors[][3] = {
{255, 164, 61}, // כתום
{241, 252, 119}, // צהוב
{255, 255, 255}, // לבן
{139, 215, 252} // כחול
};
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show();
Serial.begin(9600);
}
void loop() {
// 🟧 שלב 0: כתום – מילוי הדרגתי
Serial.println("Stage 0: Orange");
uint8_t r = colors[0][0];
uint8_t g = colors[0][1];
uint8_t b = colors[0][2];
for (int i = 0; i < NUMPIXELS; i++) {
float minFactor = 0.5;
float range = 1.0 - minFactor;
float step = float(i) / (NUMPIXELS - 1);
float factor = minFactor + step * range;
uint8_t rr = r * factor;
uint8_t gg = g * factor;
uint8_t bb = b * factor;
strip.setPixelColor(i, strip.Color(rr, gg, bb));
strip.show();
delay(150);
}
fillAllPixels(r, g, b);
bool pressedDuringSolidOrange = waitForButtonOrTimeout(10000);
if (!pressedDuringSolidOrange) {
// 🟧 לא הייתה לחיצה → נבצע הבהוב כתום עם אפשרות דילוג
bool skippedDuringBlink = blinkWithButton(r, g, b, 10000, 300);
if (skippedDuringBlink) {
Serial.println("Skipped during blinking → to Yellow");
}
} else {
Serial.println("Button pressed during solid orange → skipping blinking");
}
// 🟨 המשך לשלבים 1–3 (צהוב, לבן, כחול)
for (int c = 1; c < 4; c++) {
Serial.print("Stage ");
Serial.println(c);
uint8_t rr = colors[c][0];
uint8_t gg = colors[c][1];
uint8_t bb = colors[c][2];
strip.clear();
strip.show();
for (int i = 0; i < NUMPIXELS; i++) {
uint8_t r2 = rr, g2 = gg, b2 = bb;
if (c != 2) { // לבן – בלי הדרגת עוצמה
float minFactor = 0.5;
float range = 1.0 - minFactor;
float step = float(i) / (NUMPIXELS - 1);
float brightnessFactor = minFactor + step * range;
r2 = rr * brightnessFactor;
g2 = gg * brightnessFactor;
b2 = bb * brightnessFactor;
}
strip.setPixelColor(i, strip.Color(r2, g2, b2));
strip.show();
delay(150);
}
fillAllPixels(rr, gg, bb);
bool skip = waitForButtonOrTimeout(10000);
if (skip) {
Serial.println("Button pressed – skipping to next color");
}
if (c == 3) {
Serial.println("Finished – staying on blue.");
while (true); // עצירה מוחלטת
}
strip.clear();
strip.show();
delay(500);
}
}
bool waitForButtonOrTimeout(unsigned long durationMs) {
unsigned long start = millis();
while (millis() - start < durationMs) {
if (digitalRead(BUTTON_PIN) == LOW) {
delay(200); // נוגדן קפיצות
return true;
}
delay(20);
}
return false;
}
bool blinkWithButton(uint8_t r, uint8_t g, uint8_t b, unsigned long durationMs, int interval) {
unsigned long start = millis();
bool on = true;
while (millis() - start < durationMs) {
if (digitalRead(BUTTON_PIN) == LOW) {
delay(200);
return true;
}
if (on) {
fillAllPixels(r, g, b);
} else {
strip.clear();
strip.show();
}
on = !on;
delay(interval);
}
return false;
}
void fillAllPixels(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < NUMPIXELS; i++) {
strip.setPixelColor(i, strip.Color(r, g, b));
}
strip.show();
}