#include <LiquidCrystal_I2C.h> //מזמן סיפריית LCD
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int buzz1=13;
int buzz2=12;
int buzz3=11;
int buzz4=10;
int led1=6;
int led2=5;
int led3=4;
int g=392;
int a=440;
int b=493;
int c=523;
int d=587;
int e=659;
int f=349;
int sw=7;
int ran=0;
void setup() {
// put your setup code here, to run once:
pinMode(sw, INPUT_PULLUP);
pinMode(buzz1, OUTPUT);
pinMode(buzz2, OUTPUT);
pinMode(buzz3, OUTPUT);
pinMode(buzz4, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
lcd.begin(16,2);
lcd.backlight();
lcd.setBacklight(HIGH);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(sw)==LOW)
{
ha();
tone(buzz1, g);
delay(750);
random1();
tone(buzz1, a);
delay(500);
random1();
tone(buzz1, g);
delay(500);
random1();
tone(buzz1, c);
delay(500);
random1();
tone(buzz1, b);
delay(500);
random1();
lcd.clear();
noTone(buzz1);
delay(400);
ha();
tone(buzz1, g);
delay(750);
random1();
tone(buzz1, a);
delay(500);
random1();
tone(buzz1, g);
delay(500);
random1();
tone(buzz1, d);
delay(500);
random1();
tone(buzz1, c);
delay(500);
random1();
lcd.clear();
noTone(buzz1);
delay(400);
to();
tone(buzz1, g);
delay(750);
random1();
tone(buzz1,e);
delay(500);
random1();
tone(buzz1,c);
delay(500);
random1();
tone(buzz1,b);
delay(500);
random1();
tone(buzz1,a);
delay(750);
random1();
lcd.clear();
noTone(buzz1);
delay(400);
ha();
tone(buzz1, f);
delay(750);
random1();
tone(buzz1, e);
delay(750);
random1();
tone(buzz1, c);
delay(750);
random1();
tone(buzz1, d);
delay(600);
random1();
tone(buzz1, c);
delay(500);
random1();
}
lcd.clear();
noTone(buzz1);
}
void ha()
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Happy Birthday");
lcd.setCursor(5,1);
lcd.print("To you");
}
void to()
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Happy Birthday");
lcd.setCursor(2,1);
lcd.print("Dear [name]");
}
void random1()
{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
ran=random(1,6);
if (ran==1)
digitalWrite(led1, HIGH);
if (ran==1)
digitalWrite(led2, HIGH);
if (ran==3)
digitalWrite(led3, HIGH);
if (ran==4)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
}
if (ran==5)
{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
}
if (ran==6)
{
digitalWrite(led1, HIGH);
digitalWrite(led3, HIGH);
}
}