Laporan Akhir 1 Modul I
Laporan Percobaan 2
Keypad dan 7-segment
1. Foto Hardware dan Diagram Blok [Kembali]
Diagram Blok:
2. Prosedur Percobaan [Kembali]
+ Rangkai semua komponen
+ buat program di aplikasi arduino IDE
+ setelah selesai masukkan program ke arduino
+ jalankan program pada simulasi dan cobakan dengan modul
Prinsip Kerja
Pada rangkaian ini menggunakan komponen antara lain yaitu mikrokontroler (ATMEGA328P-PU), push button, dan 7-segment.
Prinsip kerja rangkaian ini ialah dimana push button yang merepresentasikan keypad 4x4 berfungsi sebagai input sedangkan 7-segment berfungsi sebagai output.
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'}, // Keypad 4x4 layout
{'7','8','9','C'}, {'*','0','#', 'D'}
Sesuai dengan program arduino yang sudah di buat dimana terdapat array matrix 4x4 yang merepresentasikan layout keypad, yang masing-masing karakter terkait degan tombol pada keypad. Jadi apabila kita menekan tombol pada keypad maka akan dimunculkan tulisan tombol tersebut di 7-segment.
4. Flowchart dan Listing Program [Kembali]
Listing Program:
//Percobaan 2
#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Fou 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) { displayCharacter(key); delay(1000); clearDisplay(); } } void displayCharacter(char ch) { // Define segment patterns for each digit (0-9) // Example: Displaying '1' // A // F B // G // E C // D byte patterns[][9] = { {0, 0, 0, 0, 0, 0, 1, 1}, // 0 {1, 0, 0, 1, 1, 1, 1, 1}, // 1 {0, 0, 1, 0, 0, 1, 0, 1}, // 2 {0, 0, 0, 0, 1, 1, 0, 1}, // 3 {1, 0, 0, 1, 1, 0, 0, 1}, // 4 {0, 1, 0, 0, 1, 0, 0, 1}, // 5 {0, 1, 0, 0, 0, 0, 0, 1}, // 6 {0, 0, 0, 1, 1, 1, 1, 1}, // 7 {0, 0, 0, 0, 0, 0, 0, 1}, // 8 {0, 0, 0, 0, 1, 0, 0, 1}, // 9 {0, 0, 0, 0, 0, 1, 0, 1}, //a {1, 1, 0, 0, 0, 0, 0, 1}, //b {0, 1, 1, 0, 0, 0, 1, 1}, //c {1, 0, 0, 0, 0, 1, 0, 1}, //d }; if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'D')) { // Get the digit index (0-9) 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); } }
}; 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) { displayCharacter(key); delay(1000); clearDisplay(); } } void displayCharacter(char ch) { // Define segment patterns for each digit (0-9) // Example: Displaying '1' // A // F B // G // E C // D byte patterns[][9] = { {0, 0, 0, 0, 0, 0, 1, 1}, // 0 {1, 0, 0, 1, 1, 1, 1, 1}, // 1 {0, 0, 1, 0, 0, 1, 0, 1}, // 2 {0, 0, 0, 0, 1, 1, 0, 1}, // 3 {1, 0, 0, 1, 1, 0, 0, 1}, // 4 {0, 1, 0, 0, 1, 0, 0, 1}, // 5 {0, 1, 0, 0, 0, 0, 0, 1}, // 6 {0, 0, 0, 1, 1, 1, 1, 1}, // 7 {0, 0, 0, 0, 0, 0, 0, 1}, // 8 {0, 0, 0, 0, 1, 0, 0, 1}, // 9 {0, 0, 0, 0, 0, 1, 0, 1}, //a {1, 1, 0, 0, 0, 0, 0, 1}, //b {0, 1, 1, 0, 0, 0, 1, 1}, //c {1, 0, 0, 0, 0, 1, 0, 1}, //d }; if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'D')) { // Get the digit index (0-9) 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); } }
Percobaan 2 Kondisi 2 : "Button baris 2 kolom 2 menampilkan huruf 5"
᭒ HTML↠ klik disini
᭒ Video Percobaan↠ klik disini
᭒ Rangkaian↠ klik disini
᭒ Program↠ klik disini
᭒ Datasheet Arduino↠ klik disini
᭒ Datasheet Push Button↠ klik disini
᭒ Datasheet 7 Segment↠ klik disini








0 Response to "Laporan Akhir 1 Modul I"
Posting Komentar