/*
全家便利商店來客報音
*/
byte btn=33;
byte buzzer=22;
//#中音音階---------------------------------
#define C5 523
#define D5 587	
#define E5 659	
#define F5 698	
#define G5 784	
#define A5 880	
#define B5 988
//#高音音階---------------------------------
#define C6 1047
#define D6 1175
#define E6 1319
#define F6 1397
#define G6 1568
#define A6 1760	
#define B6 1976
						
void setup() {
  Serial.begin(115200);
  pinMode(btn, INPUT_PULLUP);
  pinMode(buzzer, OUTPUT);
}
void loop() {
  if(!digitalRead(btn)) {
    while(!digitalRead(btn));
    sound();
  }
  delay(10); // this speeds up the simulation
}
//音樂播放
void sound(){
  //音階 E6 C6 G5 C6 D6 G6  0   D6 E6 D6 G5 C6
  //音長  1  1  1  1  1 2.5 0.5  1  1  1  1  2
  int t =300 ;    //基本節拍
  tone(buzzer,E6,t);  Serial.println("E6");
  tone(buzzer,C6,t);  Serial.println("C6");
  tone(buzzer,G5,t);  Serial.println("G5");
  tone(buzzer,C6,t);  Serial.println("C6");
  tone(buzzer,D6,t);  Serial.println("D6");
  tone(buzzer,G6,t*5/2); Serial.println("G6");
  tone(buzzer, 0,t/2); Serial.println("0"); //斷音
  tone(buzzer,D6,t);  Serial.println("D6");
  tone(buzzer,E6,t);  Serial.println("E6");
  tone(buzzer,D6,t);  Serial.println("D6");
  tone(buzzer,G5,t);  Serial.println("G5");
  tone(buzzer,C6,t*5/2); Serial.println("C6");
}