Kamis, 29 Februari 2024

LA M1_P2_K2

 



Percobaan 2
Keypad & 7-Segment

1. Foto Hardware dan Diagram Blok [Kembali]

     Arduino Uno
           
    

    7-Segment
        
 
 

 
    Button
        
 
 
       
 
     Keypad
        
 
 
Diagram Blok:

2. Prosedur Percobaan  [Kembali]

1. Susun semua komponen.
2. Buat program menggunakan aplikasi Arduino IDE.
3. Unggah program ke Arduino setelah selesai.
4. Jalankan program pada simulasi dan uji dengan modul.


Rangkaian Simulasi
 

Prinsip Kerja

Rangkaian ini terdiri dari beberapa komponen, termasuk mikrokontroler (ATMEGA328P-PU), push button, dan 7-segment. Prinsip kerja rangkaian ini adalah bahwa push button, yang mewakili keypad 4x4, bertindak sebagai input, sementara 7-segment bertindak sebagai output. Ada sebuah array matriks 4x4 yang merepresentasikan layout keypad dalam program Arduino, di mana setiap karakter terkait dengan tombol pada keypad. Jadi, ketika tombol pada keypad ditekan, karakter tersebut akan ditampilkan pada 7-segment. Misalnya, jika tombol pada baris 2 kolom 2 ditekan, 7-segment akan menampilkan "C" selama 1 detik sebelum kembali kosong. Hal yang sama berlaku untuk tombol "#" (pound), "*", dan tombol 0-9.

4. Flowchart dan Listing Program [Kembali]

Flowchart


http://www.plantuml.com/plantuml/png/LP31JiCm44Jl-nLpStBamALHfKgjXFWCGpPqXREsOXTalfvD33Ji8LBcpLYZEUNYbtAR0pbSU19bR0fodLzYeEs7wF2iKiG7-JBERpDhGHBDmp_opZNvSI3wl4fWT6MvSG_9w4ACgIVO7Pwuh4PCIvp_4h2J2TqAZaUuHzUZN5dHLSujk8KlabFm5Uxi41MPFrX_2mqx6w-c1oElKSSTE0Vs2yRsIjDPHvd8lgtqJzNx74RkOyH49nDihsy0
Listing Program:

#include <Keypad.h>

const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns

char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'}, // Keypad 4x4 layout
  {'7','8','9','C'},
  {'*','0','#', 'D'}
};

byte rowPins[ROWS] = {A4, A3, A2, A1}; // Connect to the keypad row pins
byte colPins[COLS] = {10, 11, 12, 13}; // Connect to the keypad column pins

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

const int segmentPins[] = {9, 8, 7, 6, 5, 4, 3, 2}; // Connect to the seven-segment display segment pins

void setup() {
  for (int i = 0; i < 8; i++) {
    pinMode(segmentPins[i], OUTPUT);
  }
}

void loop() {
  char key = keypad.getKey();
  if (key == '5') { // Check if the button "5" (row 2, column 2) is pressed
    displayCharacter('C'); // Display "C" on the seven segment
    delay(1000);
    clearDisplay();
  }
}

void displayCharacter(char ch) {
  // Define segment patterns for each digit (0-9, A-D)
  byte patterns[][8] = {
    {0, 0, 0, 0, 0, 0, 1}, // 0
    {1, 0, 0, 1, 1, 1, 1}, // 1
    {0, 0, 1, 0, 0, 1, 0}, // 2
    {0, 0, 0, 0, 1, 1, 0}, // 3
    {1, 0, 0, 1, 1, 0, 0}, // 4
    {0, 1, 0, 0, 1, 0, 0}, // 5
    {0, 1, 0, 0, 0, 0, 0}, // 6
    {0, 0, 0, 1, 1, 1, 1}, // 7
    {0, 0, 0, 0, 0, 0, 0}, // 8
    {0, 0, 0, 0, 1, 0, 0}, // 9
    {0, 0, 0, 1, 0, 0, 0}, // A
    {1, 1, 0, 0, 0, 0, 0}, // B
    {0, 1, 1, 0, 0, 0, 1}, // C
    {1, 0, 0, 0, 0, 1, 0}  // D
  };

  if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'D')) {
    // Get the digit index (0-9, A-D) from the character
    int index = (ch <= '9')? (ch - '0') : (ch - 'A' + 10);
    // Write the pattern to the segment pins
    for (int i = 0; i < 7; i++) {
      digitalWrite(segmentPins[i], patterns[index][i]);
    }
  }
}

void clearDisplay() {
  for (int i = 0; i < 8; i++) {
    digitalWrite(segmentPins[i], HIGH);
  }
}



5. Kondisi [Kembali]

Pada percobaan 2, kondisi 2, ketika tombol pada baris 2 kolom 2 ditekan, maka 7-segment akan menampilkan huruf "C".


    Download HTML
   
Download Program
   
Download Video Simulasi
    Download Datasheet 7-Segment
    Download Datasheet Button
    
Download Datasheet Arduino Uno
    Download Datasheet Keypad 4x4

 











Tidak ada komentar:

Posting Komentar

Sistem Otomatis Lampu Belajar dan Kipas Pendingin Berbasis Kehadiran dan Suara

[menuju akhir] [KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI 1. Pendahuluan 2. Tujuan 3. Alat dan Bahan 4. Dasar Teori 5. Percob...