Tugas Pendahuluan 1




1. Kondisi [Kembali]

Percobaan 5 Kondisi 1, Setiap 1 Switch aktif muncul angka sesuai jumlah switch yang aktif pada digit 1

 

2. Rangkaian Simulasi [Kembali]




 
3. Flowchart [Kembali]




 
4. Listing Program [Kembali]

#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);
}

5. Video [Kembali]




6. Link Download [Kembali]

 

No comments:

Post a Comment