Just Test

Python 線上編輯器

在Blogger 貼上程式碼一

如何在Blogger 網頁內,貼上如下圖美美的程式碼呢?一點也不困難,讓我們繼續看下去。

程式貼碼測試01

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

程式碼輸出測試三

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


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------------------------------

七段顯示器



七段顯示器是由八個LED當組成,有共陽及與共陰極兩種,在購買時要注意是屬於哪一種,在這裡要示範的是共陰極的七段顯示器。