Langkah-langkah percobaan :
4. Flowchart dan Listing Program [Kembali]
1. Siapkan alat dan bahan yaitu dengan komponen utama Arduino Uno, Infrared Sensor, IC I2C, Keypad dan Motor DC
2. Rangkai sesuai gambar percobaan
3. Rancang kerja rangkaian sesuai flowchat
4. Tekan tombol “Play” untuk menjalankan simulasi
2. Hardware dan Diagram Blok [Kembali]
3. Rangkaian Simulasi dan Prinsip Kerja [Kembali]
4. Flowchart dan Listing Program [Kembali]
flowchart:
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);
}
}
8. Download File [Kembali]
video klik di sini
html klik di sini
rangkaian klik di sini
code arduino uno klik di sini
Tidak ada komentar:
Posting Komentar