#include <Keypad.h>
#include <LiquidCrystal.h>
int i=0;
LiquidCrystal lcd (7,8,9,10,11,12);
const byte KEYPAD_ROWS = 4; //กำหนด แถวของ keypad ที่ใช้
const byte KEYPAD_COLS = 4; //กำหนด คอลัมของ keypad ที่ใข้
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2}; //กำหนดพอร์ตที่ต่อ
byte colPins[KEYPAD_COLS] = {A3, A2, A1, A0}; //กำหนดพอร์ตที่ต่อ
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
void setup() {
pinMode(6, OUTPUT);
pinMode(13,OUTPUT);
lcd.begin(20,4);
lcd.setCursor(2,0);
lcd.print("Yanisa 632021120");
lcd.setCursor(4,1);
lcd.print("Mode : Manual");
}
void loop() {
char key = keypad.getKey();
if(key =='2'){digitalWrite(6, HIGH); noTone(13); lcd.setCursor(7,2); lcd.print("LED ON");}
if(key =='9'){digitalWrite(6, LOW); tone(13, 1000); delay(100); noTone(13); lcd.setCursor(7,2); lcd.print("LED OFF");}
if(key =='A'){digitalWrite(6, HIGH); noTone(13); lcd.setCursor(7,2); lcd.print("LED ON ");
for(int i = 10; i--;) {
lcd.setCursor(4,1);
lcd.print("Mode : Auto ");
lcd.setCursor(10,3);
lcd.print(i,DEC);delay(600);
tone(13, 1000);delay(100);noTone(13);
}
if(i == 0)
{digitalWrite(6, LOW); tone(13, 1000); delay(1500); noTone(13);}
}
}