#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "pitches.h" // Include the pitches library
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define the buzzer pin
int buzzer = 13;
// Nokia Tune Melody
int melody[] = {
NOTE_E5, 8, NOTE_D5, 8, NOTE_FS4, 4, NOTE_GS4, 4,
NOTE_CS5, 8, NOTE_B4, 8, NOTE_D4, 4, NOTE_E4, 4,
NOTE_B4, 8, NOTE_A4, 8, NOTE_CS4, 4, NOTE_E4, 4,
NOTE_A4, 2
};
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
int tempo = 180;
int wholenote = (60000 * 4) / tempo;
void setup() {
// Initialize the LCD
lcd.init();
// Turn on backlight
lcd.backlight();
// Initialize pins 2 to 11 as outputs for LEDs
for (int i = 2; i <= 11; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
// Print action on LCD for even LEDs
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Even LEDs ON");
delay(1000);
// Chase LEDs with even numbers
for (int pin = 2; pin <= 11; pin += 2) {
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
}
delay(3000);
// Print action on LCD for odd LEDs
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Odd LEDs ON");
delay(1000);
// Chase LEDs with odd numbers
for (int pin = 3; pin <= 11; pin += 2) {
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
}
delay(3000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" BY ARVIND PATIL");
delay(1000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("NOKIA TUNE STARTS");
delay(1000);
// Play Nokia Tune
for (int i = 0; i < 3; i++) {
for (int thisNote = 0; thisNote < notes; thisNote++) {
// calculates the duration of each note
int noteDuration = (wholenote) / melody[thisNote * 2 + 1];
if (melody[thisNote * 2 + 1] < 0) {
noteDuration *= 1.5;
}
tone(buzzer, melody[thisNote * 2], noteDuration);
delay(noteDuration * 1.2); // slight pause between notes
noTone(buzzer);
}
delay(5000); // Pause between repetitions
}
}