程式碼輸出測試三

這是用來測試程式碼輸出的效果。


Source file
 1 // 按鍵鋼琴,利用按鈕播放音階
 2 const int speaker=2;
 3 const int sw[8]={4,5,6,7,8,9,10,11} ;
 4 const int frequency[8]={523,587,659,694,784,880,988,1046};
 5 int i ;
 6 int val ;
 7 
 8 void setup() {
 9   // put your setup code here, to run once:
10   for(int i=0;i<8;i++) 
11      pinMode(sw[i],INPUT) ;
12 
13 }
14 
15 void loop() {
16   // put your main code here, to run repeatedly:
17   for(int i=0;i<8;i++) {
18     val = digitalRead(sw[i]) ;
19     
20     if (val==1){
21         tone(speaker,frequency[i],100) ;
22      }
23    }
24 
25 }
----------------------------------------------------------------- 另一個文件的開始--------------
 1 // 按鍵鋼琴,利用按鈕播放音階
 2 const int speaker=2;
 3 const int sw[8]={4,5,6,7,8,9,10,11} ;
 4 const int frequency[8]={523,587,659,694,784,880,988,1046};
 5 int i ;
 6 int val ;
 7 
 8 void setup() {
 9   // put your setup code here, to run once:
10   for(int i=0;i<8;i++) 
11      pinMode(sw[i],INPUT) ;
12 
13 }
14 
15 void loop() {
16   // put your main code here, to run repeatedly:
17   for(int i=0;i<8;i++) {
18     val = digitalRead(sw[i]) ;
19     
20     if (val==1){
21         tone(speaker,frequency[i],100) ;
22      }
23    }
24 
25 }
--------------------------------------END------------------------------