Percobaan 2 - Kondisi 2:
Tampilkan angka dari 1 sampai 9 secara berulang
Rangkaian Simulasi [Kembali]
Video
[Kembali]
Prinsip Kerja [Kembali]
list code:
byte pin[] = {2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
pinMode (2,OUTPUT);
pinMode (3,OUTPUT);
pinMode (4,OUTPUT);
pinMode (5,OUTPUT);
pinMode (6,OUTPUT);
pinMode (7,OUTPUT);
pinMode (8,OUTPUT);
pinMode (9,OUTPUT);
}
void loop() {
one();
two();
three();
four();
five();
six();
seven();
eight();
nine();
}
void one(){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(500);
}
void two(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(500);
}
void three (){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(500);
}
void four(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(500);
}
void five(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(500);
}
void six(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(500);
}
void seven(){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(500);
}
void eight(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(500);
}
void nine(){
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(500);
}
penjelasan:
Mulanya ada variabel pin berisikan angka 2-9 fungsinya untuk mendeklarasikan pin yg akan digunakan, yaitu pin 2-9
Lalu ada fungsi setup dimana kode dalam fungsi ini dibaca sekali.
Di dalam fungsi setup ada pinMode yang menyatakan pin yang dihubungkan ke pin 2-9 fungsinya sebagai output
lalu ada fungsi loop dimana kode dalam fungsi ini dilakukan perulangan
di Dalam fungsi loop ada pemanggilan fungsi one(), two(), ... , sampai nine() agar 7 segment menampilkan angka 1-9 secara berulang.
Lalu ada fungsi one() yang berisikan
pin 2 memberikan logika LOW atau mati
pin 3, LOW);
pin 4, LOW);
pin 5, LOW);
pin 6, LOW);
pin 7, HIGH);
pin 8, HIGH);
pin 9, LOW);
lalu di delay selama 500ms atau 0,5 detik untuk menampilkan angka 1 di seven segment.
Kemudian ada fungsi two() yang berisikan
pin 2 memberikan logika LOW atau mati
pin 3, HIGH);
pin 4, LOW);
pin 5, HIGH);
pin 6, HIGH);
pin 7, LOW);
pin 8, HIGH);
pin 9, HIGH);
lalu di delay selama 500ms atau 0,5 detik untuk menampilkan angka 2 di seven segment.
begitu seterusnya higga fungsi nine()
pin 2, LOW);
pin 3, HIGH);
pin 4, HIGH);
pin 5, LOW);
pin 6, HIGH);
pin 7, HIGH);
pin 8, HIGH);
pin 9, HIGH);
lalu di delay selama 500ms atau 0,5 detik untuk menampilkan angka 9 di seven segment.
Hingga mencapai 9, maka akan menampilkan angka 1, 2, 3,... 9 dan begitu seterusnya.
Link Download
[Kembali]