Tutorial Arduino UNO R3 Counter Up & Down 7 Segment Menggunakan Push Button

Indobot Academy

Arduino Uno
Arduino Uno

Hallo Sahabat Indobot… Sebelumnya Indobot telah membagikan Tutorial Arduino UNO R3  Counter Down 7 Segment Menggunakan  Push Button. Sebagai pengembangannya kali ini kita akan membagikan Tutorial Arduino UNO R3  Counter Up & Down 7 Segment Menggunakan Push Button. Silahkan ikuti tutorial dibawah ini :


1.Alat dan Bahan

  1. Komputer yang terinstal Arduino IDE          1 unit
  2. Push Button                                                       2 buah
  3. 7 Segment Common Anode                          1 buah
  4. Resistor 220 Ohm                                           3 buah
  5. Kabel Penghubung                                         Secukupnya

2.Gambar Rangkaian

Gambar Rangkaian Seven Segmen dan Dua Push Button
Gambar Rangkaian Seven Segmen dan Dua Push Button

3.Programming

Berikut adalah Program dari Tutorial Arduino UNO R3  Counter Up & Down 7 Segment Menggunakan  Push Button :

Belajar elektronika step by step dengan bantuan tangga belajar? Regitrasi dulu dan dapatkan konsultasi dari kami!

int A = 2;

int B = 3;

int C = 4;

int D = 6;

int DP = 5;

int E = 7;

int F = 8;

int G = 9;

 

int switchUpPin = 13;

int switchDownPin = 12;

int counter = 0;

int buttonUpState = 0;

int lastButtonUpState = 0;

int buttonDownState = 0;

int lastButtonDownState = 0;

 

void setup()

{

Serial.begin(9600);

 

pinMode(A, OUTPUT);

pinMode(B, OUTPUT);

pinMode(C, OUTPUT);

pinMode(D, OUTPUT);

pinMode(E, OUTPUT);

pinMode(F, OUTPUT);

pinMode(G, OUTPUT);

pinMode(DP, OUTPUT);

 

digitalWrite(DP ,HIGH);

}

 

void loop()

{

buttonUpState = digitalRead(switchUpPin);

buttonDownState = digitalRead(switchDownPin);

 

if (buttonUpState != lastButtonUpState)

{

if (buttonUpState == HIGH)

{

if(counter == 9)

{

counter = -1;

}

counter++;

Serial.println(counter);

changeNumber(counter);

delay(300);

}

else

{

Serial.println(“OFF”);

}

delay(50);

}

 

 

if (buttonDownState != lastButtonDownState)

{

if (buttonDownState == HIGH)

{

if(counter == 0)

{

counter = 10;

}

counter–;

Serial.println(counter);

changeNumber(counter);

delay(300);

}

else

{

Serial.println(“OFF”);

}

delay(50);

}

changeNumber(counter);

}

 

 

 

 

 

void changeNumber(int buttonPress)

{

switch (buttonPress)

{

//number 0

case 0:

digitalWrite(A, LOW);

digitalWrite(B, LOW);

digitalWrite(C, LOW);

digitalWrite(D, LOW);

digitalWrite(E, LOW);

digitalWrite(F, LOW);

digitalWrite(G, HIGH);

break;

//number 1

case 1:

digitalWrite(A, HIGH);

digitalWrite(B, LOW);

digitalWrite(C, LOW);

digitalWrite(D, HIGH);

digitalWrite(E, HIGH);

digitalWrite(F, HIGH);

digitalWrite(G, HIGH);

break;

//number 2

case 2:

digitalWrite(A, LOW);

digitalWrite(B, LOW);

digitalWrite(C, HIGH);

digitalWrite(D, LOW);

digitalWrite(E, LOW);

digitalWrite(F, HIGH);

digitalWrite(G, LOW);

break;

//number 3

case 3:

digitalWrite(A, LOW);

digitalWrite(B, LOW);

digitalWrite(C, LOW);

digitalWrite(D, LOW);

digitalWrite(E, HIGH);

digitalWrite(F, HIGH);

digitalWrite(G, LOW);

break;

//number 4

case 4:

digitalWrite(A, HIGH);

digitalWrite(B, LOW);

digitalWrite(C, LOW);

digitalWrite(D, HIGH);

digitalWrite(E, HIGH);

digitalWrite(F, LOW);

digitalWrite(G, LOW);

break;

//number 5

case 5:

digitalWrite(A, LOW);

digitalWrite(B, HIGH);

digitalWrite(C, LOW);

digitalWrite(D, LOW);

digitalWrite(E, HIGH);

digitalWrite(F, LOW);

digitalWrite(G, LOW);

break;

//number 6

case 6:

digitalWrite(A, LOW);

digitalWrite(B, HIGH);

digitalWrite(C, LOW);

digitalWrite(D, LOW);

digitalWrite(E, LOW);

digitalWrite(F, LOW);

digitalWrite(G, LOW);

break;

//number 7

case 7:

digitalWrite(A, LOW);

digitalWrite(B, LOW);

digitalWrite(C, LOW);

digitalWrite(D, HIGH);

digitalWrite(E, HIGH);

digitalWrite(F, HIGH);

digitalWrite(G, HIGH);

break;

//number 8

case 8:

digitalWrite(A, LOW);

digitalWrite(B, LOW);

digitalWrite(C, LOW);

digitalWrite(D, LOW);

digitalWrite(E, LOW);

digitalWrite(F, LOW);

digitalWrite(G, LOW);

break;

//number 9

case 9:

digitalWrite(A, LOW);

digitalWrite(B, LOW);

digitalWrite(C, LOW);

digitalWrite(D, LOW);

digitalWrite(E, HIGH);

digitalWrite(F, LOW);

digitalWrite(G, LOW);

break;

}

}

 

Ketikkan Ptogram diatas pada Aarduino IDE kalian, hubungkan Board arduino dengan Komputer menggunakan USB Arduino kemudian upload program ke Board Arduino. Pastikan proses upload selesai dan berhasil.

Setelah Program Selesai di Upload silahkan Pencet pada kedua Push Button secara bergantian dan lihatlah yang terjadi pada 7 Segment.

Sampai disini dulu tutorial Arduino UNO kali ini ya sahabat Indobot. Setelah berhasil mencoba tutorial ini silahkan pahami programnya dan kembangkan sesuai keinginan kalian.  Sampai ketemu lagi di tutorial selanjutnya….

Bikin project tanpa ribet beli komponen sana-sini? Starter Kit Arduino/IoT bisa jadi solusi mu!

Ingin Tahu Program Kami Lebih Lanjut?

Silahkan isi Formulir Dibawah Ini untuk Diskusi dengan Tim Indobot Academy.

Baca Juga

Bagikan:

Tags

Tinggalkan komentar

whatsapp whatsapp