//Library version:1.1
#include <LiquidCrystal_I2C.h>
#define NOTE_C4 262
#define NOTE_D4 294
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_G4 392
#define NOTE_A4 440
#define NOTE_B4 494
#define SPEAKER_PIN 8
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int tune_01[] = {NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4};
int note_time = 300;
int gap_time = 100;
int no_notes = 7; //the number of notes in the tunes array
int potpin = 0; // analog pin used to connect the potentiometer
int val;
void setup() {
pinMode(SPEAKER_PIN, OUTPUT);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 100, 500);
note_time=val; // scale it to use it with the servo (value between 0 and 180) // sets the servo position according to the scaled value
for (int i = 0; i < no_notes; i++) {
tone(SPEAKER_PIN, tune_01[i], note_time);
lcd.setCursor(2,3);
lcd.print(tune_01[i]);
delay(note_time+gap_time);
}
}