寫程式18.jpg

💽影片名稱:[Arduino寫程式] 第18集 - 七段顯示器 陣列程式

🎬集數:18集💕若有問題歡迎在下方留言💬讓我知道~😋


🌐(前往YouTube觀看)-[ https://youtu.be/MgAiDZXJmUY?feature=shared ]

🌐(YouTube播放清單)-[ https://youtube.com/playlist?list=PLOrdAySpFIQonYKEWANFiVrICDQY8R0_1&feature=shared ]


🌐程式創造++ 頻道:[ https://www.youtube.com/@CCplus2561 ]🌐Arduino程式語法網頁:[ https://www.86duino.com/?page_id=2255&lang=TW ]


[電路圖]

寫程式16 - 七段顯示器 共陰極 電路圖.png

▲ 電路圖由 @CCplus2561 提供 ( Fritzing軟體 )

七段顯示器 數字顯示.png

▲ 此素材圖片由Google圖片提供

寫程式15 - 七段顯示器 共陽極 素材1.png

▲ 此素材圖片由Google圖片提供

寫程式15 - 七段顯示器 共陽極 素材2.png

▲ 此素材圖片由Google圖片提供


[程式碼]

EX01: [錯誤示範]七段顯示器 顯示數字0~9
int dog[10][8]={{1,1,1,1,1,1,0,0},  //0
                {0,1,1,0,0,0,0,0},  //1
                {1,1,0,1,1,0,1,0},  //2
                {1,1,1,1,0,0,1,0},  //3
                {0,1,1,0,0,1,1,0},  //4
                {1,0,1,1,0,1,1,0},  //5
                {1,0,1,1,1,1,1,0},  //6
                {1,1,1,0,0,1,0,0}   //7
                {1,1,1,1,1,1,1,0},  //8
                {1,1,1,1,0,1,1,0}}; //9
int pin[]={22,23,24,25,26,27,28,29};
int a,b,c;
 
void setup() {
 for(a=22; a<=29; a++)pinMode(a, OUTPUT);
}
 
void loop() {
 for(a=22; a<=29; a++)cww(b);delay(500);
}
 
void cww(int c) {
 for(a=0; a<=8; a++)digitalWrite(pin[a], dog[c][a]);
}

EX02: 七段顯示器 顯示數字0~9
int dog[10][8]={{1,1,1,1,1,1,0,0},  //0
                {0,1,1,0,0,0,0,0},  //1
                {1,1,0,1,1,0,1,0},  //2
                {1,1,1,1,0,0,1,0},  //3
                {0,1,1,0,0,1,1,0},  //4
                {1,0,1,1,0,1,1,0},  //5
                {1,0,1,1,1,1,1,0},  //6
                {1,1,1,0,0,1,0,0}   //7
                {1,1,1,1,1,1,1,0},  //8
                {1,1,1,1,0,1,1,0}}; //9
int pin[]={22,23,24,25,26,27,28,29};
int a,b,c;
 
void setup() {
 for(a=22; a<=29; a++){pinMode(a, OUTPUT);
}
 
void loop() {
 for(a=22; a<=29; a++){
  cww(b);delay(500);
 }
}
 
void cww(int c) {
 for(a=0; a<=8; a++){
  digitalWrite(pin[a], dog[c][a]);
 }
}

EX03: 七段顯示器 顯示數字0.2.4.6.8
int dog[10][8]={{1,1,1,1,1,1,0,0},  //0
                {0,1,1,0,0,0,0,0},  //1
                {1,1,0,1,1,0,1,0},  //2
                {1,1,1,1,0,0,1,0},  //3
                {0,1,1,0,0,1,1,0},  //4
                {1,0,1,1,0,1,1,0},  //5
                {1,0,1,1,1,1,1,0},  //6
                {1,1,1,0,0,1,0,0}   //7
                {1,1,1,1,1,1,1,0},  //8
                {1,1,1,1,0,1,1,0}}; //9
int pin[]={22,23,24,25,26,27,28,29};
int a,b,c;
 
void setup() {
 for(a=22; a<=29; a++){pinMode(a, OUTPUT);
}
 
void loop() {
 for(a=22; a<=29; a++){
  cww(b);delay(500);
 }
}
 
void cww(int c) {
 for(a=0; a<=8; a++){
  cww(0);delay(500);
  cww(2);delay(500);
  cww(4);delay(500);
  cww(6);delay(500);
  cww(8);delay(500);
 }
}
創作者介紹
創作者 Code Create++ 的頭像
程式創造++

Code Create++

程式創造++ 發表在 痞客邦 留言(0) 人氣( 0 )