{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(2,INPUT);//do
pinMode(3,INPUT);//re
pinMode(4,INPUT);//mi
pinMode(9,OUTPUT);
/* 这里用了一个sizeof函数, 可以查出tone序列里有多少个音符 */
length = sizeof(tune)/sizeof(tune[0]);
pinMode(buttonPin, INPUT_PULLUP);
lcd.clear();
}
int p;
void loop()
{
// set the cursor to column 0, line 1
lcd.setCursor(0, 0);
lcd.print("MUSIC PLAYER");//print name
//print name
delay(750);//delay of 0.75sec
// set the cursor to column 0, line1
noTone(9);
if(digitalRead(2)==HIGH)
{
tone(9,523);
lcd.setCursor(0, 1);
lcd.print("DO");
}
else if(digitalRead(3)==HIGH)
{
tone(9,587);
lcd.setCursor(0, 1);
lcd.print("RE");
}
else if(digitalRead(4)==HIGH)
{
tone(9,659);
lcd.setCursor(0, 1);
lcd.print("MI");
}
delay(5);
for (int x = 0; x < length; x++)
{
if (digitalRead(buttonPin) == HIGH) {//如果读取到按键被按压改变ledStart
ledState = !ledState ;
delay(500);//这个延迟是你按压按键的大概时间
p = x;//记录当前播放的音乐的位置
}