#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
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
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 potentiometer_pin = A0;
int potentiometer_value;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(7,0);
lcd.print("Hello!");
lcd.setCursor(3,1);
lcd.print("Move The Slider");
lcd.setCursor(4,2);
lcd.print("To Play Notes");
lcd.setCursor(6,3);
lcd.print("Of A Song!");
potentiometer_value = analogRead(potentiometer_pin);
pinMode(SPEAKER_PIN, OUTPUT);
}
void loop() {
potentiometer_value = analogRead(potentiometer_pin);
note_time = map(potentiometer_value, 100, 500, 100,500);
for (int i = 0; i < no_notes; i++) {
tone(SPEAKER_PIN, tune_01[i], note_time);
delay(note_time+gap_time);
}
}