/*
Wokwi | general
Tasneeem — 9/23/25 2:47 PM
Project Link: https://wokwi.com/projects/442733727128674305?gh=1
Error message: Failed to fetch
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int redLedPin = 6;
const int yellowLedPin = 5;
const int greenLedPin = 4;
const int buzzerPin = 3;
const int buttonPin = 2;
int donationCount = 0;
int goal = 30;
String messages[] = {
"You give hope!",
"Thank you! <3",
"Every bit helps",
"Free Palestine",
"Solidarity!",
"Hope is rising"
};
int numMessages = 6;
long lastDebounceTime = 0;
long debounceDelay = 50;
int lastButtonState = HIGH;
void setup() {
lcd.init();
lcd.backlight();
pinMode(buttonPin, INPUT_PULLUP);
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
randomSeed(analogRead(0));
updateDisplay();
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading == LOW) {
donationCount++;
tone(buzzerPin, 1000, 100);
updateDisplay();
if (donationCount < goal) {
// من 1 إلى 29 → فلاش واحد (يضوي ثم يطفي)
if (donationCount <= goal / 3) {
flashLed(redLedPin);
} else if (donationCount <= (goal * 2) / 3) {
flashLed(yellowLedPin);
} else {
flashLed(greenLedPin);
}
} else if (donationCount == goal) {
// المرة 30 → احتفال
celebrateGoal();
}
delay(500);
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(messages[random(numMessages)]);
delay(1500);
updateDisplay();
while (digitalRead(buttonPin) == LOW) {}
}
}
lastButtonState = reading;
}
void updateDisplay() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Donations: " + String(donationCount));
lcd.setCursor(0, 1);
lcd.print("For Palestine <3");
}
// فلاش واحد
void flashLed(int pin) {
digitalWrite(pin, HIGH);
delay(300);
digitalWrite(pin, LOW);
}
// الاحتفال عند الوصول للهدف
void celebrateGoal() {
for (int i = 0; i < 8; i++) {
digitalWrite(redLedPin, HIGH);
digitalWrite(yellowLedPin, HIGH);
digitalWrite(greenLedPin, HIGH);
tone(buzzerPin, 1500, 150);
delay(200);
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(greenLedPin, LOW);
delay(200);
}
}