Integrasi Arduino Atmega,Keypad, LCD, Buzzer

 #include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <LiquidCrystal.h>

#include <LiquidCrystal_I2C.h>

#include <Keypad.h>

#include <Servo.h>

#include <TM1637Display.h>


//OLED

#define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 32 

#define OLED_RESET 4 

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


//LCD

//const int rs = 44, en = 42, d4 = 52, d5 = 50, d6 = 48, d7 = 46;

//LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

LiquidCrystal_I2C lcd(0x27, 20, 4);


//LED

const int greenLedPin = 7; // Pin connected to the green LED

const int yellowLedPin = 8; // Pin connected to the yellow LED

const int redLedPin = 9; // Pin connected to the red LED

int kondisi;


//KEYPAD

const int ROW_NUM = 4; //four rows

const int COLUMN_NUM = 4; //four columns

char keys[ROW_NUM][COLUMN_NUM] = {

  {'1','2','3', 'A'},

  {'4','5','6', 'B'},

  {'7','8','9', 'C'},

  {'*','0','#', 'D'}

};

byte pin_rows[ROW_NUM] = {23, 25, 27, 29}; //connect to the row pinouts of the keypad

byte pin_column[COLUMN_NUM] = {31, 33, 35, 37}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );


//SERVO

//Servo myservo;

//int potpin = 0;

//int val;


// Konfigurasi pin TM1637

const int CLK = 2;

const int DIO = 3;

TM1637Display tm_display(2, 3);


//BUZZER

const int buzzerPin = 4; // Pin yang terhubung dengan buzzer


//ULTRASONIC

const int trigPin = 9;

const int echoPin = 10;


//deklarasi poten

int pot = A0;

float nilaiPot;

float nilaiMappingPot;


//LOGIN

String password = "0296";

String inputPassword = "";


void setup() {

  pinMode(buzzerPin, OUTPUT);

  pinMode(greenLedPin, OUTPUT);

  pinMode(yellowLedPin, OUTPUT);

  pinMode(redLedPin, OUTPUT);

  pinMode(pot, INPUT);


  lcd.init();

  lcd.backlight();

  lcd.setCursor(3, 0);

  lcd.print(" - WELCOME - ");

  lcd.setCursor(1, 1);

  lcd.print(" - Ujian Praktek- ");

  lcd.setCursor(0, 2);

  lcd.print(" - Mikrokontroller- ");

  lcd.setCursor(3, 3);

  lcd.print(" - 2022/2023 - ");

  awal();

  delay(200);

  lcd.clear();

}


void loop() {

  tahap();

}


void password1()

{

    lcd.init();

  lcd.setCursor(2, 1);

  lcd.print("Enter Password:");

  

  while (inputPassword.length() < password.length())

  {

    char key = keypad.getKey();

    if (key != NO_KEY)

    {

      inputPassword += key;

      lcd.setCursor(inputPassword.length() -1 ,2); // Menetapkan posisi kursor ke kolom yang sama dengan panjang string inputPassword saat ini dikurangi 1, dan baris 1 (baris kedua)

      lcd.print("*"); // Menampilkan karakter '*' di posisi kursor

    }

  }

  

  if (inputPassword == password)

  {

    lcd.clear();

    lcd.setCursor(0,0);

    lcd.print("Access Granted");

    delay(3000);

    inputPassword="";

  }

  else

  {

    lcd.clear();

    lcd.setCursor(0,0);

    lcd.print("Access Denied");

    delay(3000);

    inputPassword="";

  }

}


void awal()

{

  for (int i = 0; i < 2; i++) {

    digitalWrite(redLedPin, HIGH);

    digitalWrite(buzzerPin, HIGH);

    delay(500);

    digitalWrite(redLedPin, LOW);

    digitalWrite(buzzerPin, LOW);

    delay(500);

    digitalWrite(yellowLedPin, HIGH);

    digitalWrite(buzzerPin, HIGH);

    delay(500);

    digitalWrite(yellowLedPin, LOW);

    digitalWrite(buzzerPin, LOW);

    delay(500);

    digitalWrite(greenLedPin, HIGH);

    digitalWrite(buzzerPin, HIGH);

    delay(500);

    digitalWrite(greenLedPin, LOW);

    digitalWrite(buzzerPin, LOW);

    delay(500);

  }

}


void tahap() {

  lcd.clear(); // Clear the LCD

  lcd.setCursor(0,0);

  lcd.print("Tahap 1 : potensio");

  lcd.setCursor(0,1);

  lcd.print("Tahap 2 : sensor");

  lcd.setCursor(0,2);

  lcd.print("Tahap 3 : Counting");

  

  bool inMenu = true;

  bool conditionA = false;

  bool conditionB = false;

  bool conditionC = false;

  

  while (inMenu) {

    char key = keypad.getKey();

    if (key != NO_KEY) {

      if (key == 'A') {

        if (conditionB) {

          // do nothing

        }

        else if (conditionC) {

          // do nothing

        } 

        else{

        conditionA = true;

        lcd.clear();

        poten();

        }

      } else if (key == 'B') {

        if (conditionA) {

          // do nothing

        } 

        else if (conditionC) {

          // do nothing

        } else {

          conditionB = true;

          lcd.clear();

          lcd.setCursor(0,0);

          lcd.print("Uprak");

        }

      } else if (key == 'C') {

        if (conditionA) {

          // do nothing

        }

        else if (conditionB) {

          // do nothing

        } else {

        conditionC = true;

        lcd.clear();

        lcd.setCursor(0,0);

        lcd.print("2023");

        }

      } else if (key == '#') {

        inMenu = false; // Exit the while loop when '#' is pressed

      }

    }

  }

}



void poten()

{

  kondisi = 1;            //terakhir edit

  while(kondisi == true)

  {

  nilaiPot = analogRead(pot);

  nilaiMappingPot = map(nilaiPot, 0, 1023, 0, 100);

  lcd.setCursor(0,0);

  lcd.print(nilaiMappingPot);

 delay(100);

     char key = keypad.getKey();

    if (key == '#') {

      kondisi = false;

    }

  }

}


//https://slimeseru.blogspot.com/2023/06/latihan-ujian-praktek-mekatronika.html

//gg.gg/mikrow


Komentar