7 Segment 

โค้ดตัวอย่าง

void setup() {
pinMode (11,OUTPUT);
pinMode (10,OUTPUT);
pinMode (9,OUTPUT);
pinMode (8,OUTPUT);
pinMode (7,OUTPUT);
pinMode (6,OUTPUT);
pinMode (5,OUTPUT);
}
void loop() {
   mul();
  kill();
}
void mul () {
  digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,LOW);
digitalWrite(5, HIGH);
delay (1000);
digitalWrite(11,  HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, HIGH);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,HIGH);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, HIGH);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
}
void kill (){
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, HIGH);
delay (1000);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,HIGH);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11,  HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, HIGH);
delay (1000);
}
วิธีทำ
เรากำหนดขา 11,10,9,8,7,6,5 เป็น OUTPUTpinMode (11,OUTPUT);
pinMode (10,OUTPUT);
pinMode (9,OUTPUT);
pinMode (8,OUTPUT);
pinMode (7,OUTPUT);
pinMode (6,OUTPUT);
pinMode (5,OUTPUT);
ใน void set upจากนั้น จะทำเป็นเลข เขียน code ดังนี้
digitalWrite(11,  HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, HIGH);
delay (1000);
เลข 2
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,HIGH);
digitalWrite(5, LOW);
delay (1000);
เลข 3
digitalWrite(11, LOW);
digitalWrite(10, LOW); 
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, LOW);
delay (1000);
เลข 4
digitalWrite(11, HIGH);
digitalWrite(10, LOW); 
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
เลข 5
digitalWrite(11, LOW);
digitalWrite(10, HIGH); 
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
เลข 6
digitalWrite(11, HIGH);
digitalWrite(10, HIGH); 
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
เลฃ 7
digitalWrite(11, LOW);
digitalWrite(10, LOW); 
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, HIGH);
delay (1000);
เลข 8

digitalWrite(11, LOW);
digitalWrite(10, LOW); 
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
เลข 9
digitalWrite(11, LOW);
digitalWrite(10, LOW); 
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,LOW);
digitalWrite(5, LOW);
delay (1000);
digitalWrite(11,  HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6,HIGH);
digitalWrite(5, HIGH);
delay (1000);
ตั้งฟังก์ชั่น  mul();   kill(); เพื่อจะได้ไม่สับสนต่อการเขียนจะแบบไหนก็ได้ เอาขาที่กำหนดไปใส่   mul(); (0-9) kill(); (8-1) เขียนต่อ 
จากนั้น เอา ภาษา ไปใส่ Arduino แล้ว 7 Segment จะเป็นเลข0-9 และ 8-1

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้