Created
May 15, 2021 10:36
-
-
Save ecehan-civril/a39c86209062c1d991e33630d76ad2cb to your computer and use it in GitHub Desktop.
4x4 keypad hesap makinesi uygulaması
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal_I2C.h> //LCD ekran kütüphanesi | |
LiquidCrystal_I2C lcd(0x27, 16, 2); // Bu kodu kullanırken ekranda yazı çıkmaz ise 0x27 yerine 0x3f yazınız | |
#include <Keypad.h> //keypad kütüphanesi | |
const byte ROWS = 4; //satır | |
const byte COLS = 4; //sutun | |
char keys [ROWS] [COLS] = { | |
{'1', '2', '3', '+'}, | |
{'4', '5', '6', '-'}, | |
{'7', '8', '9', '*'}, | |
{'C', '0', '=', '/'} | |
}; | |
byte rowPins[ROWS] = {9, 8, 7, 6}; // satır pinleri | |
byte colPins[COLS] = {5, 4, 3, 2}; // sutun pinleri | |
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); | |
boolean presentValue = false;leblebi | |
boolean next = false; | |
boolean final = false; | |
String num1, num2; | |
float answer = 0; | |
char op; | |
void setup() | |
{ | |
lcd.init(); | |
lcd.backlight(); // arka plan ısıgı | |
lcd.setCursor(0,0); // cursor baslangıc | |
lcd.print("Robolink"); | |
lcd.setCursor(0,1); // cursor baslangıc | |
lcd.print("Teknoloji"); | |
delay(2000); | |
lcd.clear(); | |
} | |
void loop() | |
{ | |
char key = myKeypad.getKey(); | |
if (key != NO_KEY && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0')) | |
{ | |
if (presentValue != true) | |
{ | |
num1 = num1 + key; | |
int numLength = num1.length(); | |
lcd.setCursor(0, 0); | |
lcd.print(num1); | |
} | |
else | |
{ | |
num2 = num2 + key; | |
int numLength = num2.length(); | |
int numLength1 = num1.length(); | |
lcd.setCursor(1 + numLength1, 0); | |
lcd.print(num2); | |
final = true; | |
} | |
} | |
else if (presentValue == false && key != NO_KEY && (key == '/' || key == '*' || key == '-' || key == '+')) | |
{ | |
if (presentValue == false) | |
{ | |
int numLength = num1.length(); | |
presentValue = true; | |
op = key; | |
lcd.setCursor(0 + numLength, 0); | |
lcd.print(op); | |
} | |
} | |
else if (final == true && key != NO_KEY && key == '=') | |
{ | |
if (op == '+') | |
{ | |
answer = num1.toInt() + num2.toInt(); | |
} | |
else if (op == '-') | |
{ | |
answer = num1.toInt() - num2.toInt(); | |
} | |
else if (op == '*') | |
{ | |
answer = num1.toInt() * num2.toInt(); | |
} | |
else if (op == '/') | |
{ | |
answer = num1.toFloat() / num2.toFloat(); | |
} | |
lcd.clear(); | |
lcd.setCursor(0, 0); | |
lcd.print("="); | |
lcd.print(answer); | |
lcd.noAutoscroll(); | |
} | |
else if (key != NO_KEY && key == 'C') | |
{ | |
lcd.clear(); | |
presentValue = false; | |
final = false; | |
num1 = ""; | |
num2 = ""; | |
answer = 0; | |
op = ' '; | |
} | |
} |
MEKATRONNMHMNMBN
commented
Apr 1, 2022
•
- kod Çok iyi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment