TUGAS PENDAHULUAN 2

MODUL 1 PERCOBAAN 2 KONDISI 3

      [KEMBALI KE MENU SEBELUMNYA]  




Percobaan 2

Keypad dan 7-Segment

1. Prosedur  [back]

  • Rangkailah seperti rangkaian berikut
  • Buka Arduino IDE dan masukan listing program
  • Upload program ke arduino

2. Foto Hardware dan diagram blok [back]

    1. Arduino Uno

    2. KeyPad




    3. 7-Segment



    4. Power supply

    5. Ground



3. Rangkaian Simulasi dan Prinsip Kerja  [back]


                                                    Gambar 1. Rangkaian Simulasi.

Prinsip Kerja:

    Pada rangkaian percobaan 2 kondisi 3 ini menggunakan Keypad dan 7-Segment.Keypad yang berfungsi sebagai input dan 7-Segment berfungsi sebagai output. Dimana ketika keypad ditekan maka akan muncul di 7-Segment karena 7-Segment yang digunakan adalah Common Katoda maka LED pada 7-Segment akan menyala jika dalam kondisi  LOW (0).

4. Flowchart dan Listing Program  [back]

Flowchart:



  • Listing Program:
//Percobaan 2
#include <Keypad.h>

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

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

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

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

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

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

void loop() {
 char key = keypad.getKey();
 if (key) {
  Serial.println(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, 0}, // 0
   {1, 0, 0, 1, 1, 1, 1, 0}, // 1
   {0, 0, 1, 0, 0, 1, 0, 0}, // 2
   {0, 0, 0, 0, 1, 1, 0, 0}, // 3
   {1, 0, 0, 1, 1, 0, 0, 0}, // 4
   {0, 1, 0, 0, 1, 0, 0, 0}, // 5
   {0, 1, 0, 0, 0, 0, 0, 0}, // 6
   {0, 0, 0, 1, 1, 1, 1, 0}, // 7
   {0, 0, 0, 0, 0, 0, 0, 0}, // 8
   {0, 0, 0, 0, 1, 0, 0, 0}, // 9
   {0, 0, 0, 0, 0, 1, 0, 0}, //a
   {1, 1, 0, 0, 0, 0, 0, 0}, //b
   {1, 1, 1, 0, 0, 1, 0, 0}, //c
   {1, 0, 0, 0, 0, 1, 0, 0}, //d
   {0, 0, 1, 0, 0, 0, 0, 0}, //e
   {0, 1, 1, 1, 0, 0, 0, 0}, //f
 
 };
 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);
 }
}

5. Video Simulasi  [back]


7. Download File  [back]

Komentar

Postingan Populer