TP2 M1
1. Prosedur [Kembali]
- Rangkai semua komponen
- Buat program di aplikasi arduino IDE
- Setelah selesai masukkan program ke arduino
- Jalankan program pada simulasi dan cobakan sesuai kondisi
Pada Percobaan 5 memiliki input berupa 4-Dip Switch dan output berupa seven segment 2 digit jenis katoda(led segment aktif ketika berlogika HIGH). Pada percobaan ini, jumlah switch yang aktif nilainya akan ditampilkan pada digit pertama seven segment.
- Flowchart
- Listing Program
#define s1 A1
#define s2 A2
#define s3 A3
#define s4 A4
#define a 13
#define b 12
#define c 11
#define d 10
#define e 9
#define f 8
#define g 7
#define digit1 6
#define digit2 5
int sw_on, puluhan, satuan;
void setup() {
pinMode(s1, INPUT);
pinMode(s1, INPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
}
void angka(int xx){
if(xx==0){
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
}
if(xx==1){
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
if(xx==2){
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
if(xx==3){
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
if(xx==4){
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}
}
void setAngka(int xxx) {
if (xxx < 10) {
puluhan = 0;
satuan = xxx;
} else if (xxx < 100) {
puluhan = xxx / 10;
satuan = xxx % 10;
}
digitalWrite(digit1, LOW);
digitalWrite(digit2, HIGH);
angka(puluhan);
delay(50);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
angka(satuan);
delay(50);
}
void penjumlahan(){
int sw1 = digitalRead(s1);
int sw2 = digitalRead(s2);
int sw3 = digitalRead(s3);
int sw4 = digitalRead(s4);
sw_on = sw1+sw2+sw3+sw4;
}
void loop() {
penjumlahan();
setAngka(sw_on);
}
Setiap 1 Switch aktif muncul angka sesuai jumlah switch yang aktif pada digit 1
x HTML klik disini
Simulasi klik disini
Gambar Simulasi klik disini
x Video Simulasi klik disini
Listring Program klik disini
x Video Simulasi klik disini
Listring Program klik disini
Komentar
Posting Komentar